我在我的应用程序中使用广播接收器。我的应用程序中有很多活动。在 MainActivity.java 中使用的 Broadcard 接收器如下:
private BroadcastReceiver smsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
Run Code Online (Sandbox Code Playgroud)
当消息到来并且 MyActivity 处于焦点时,我会发出通知。现在,当我关注其他活动时,我没有收到通知。有没有一种通用的方法可以将 BroadCast 用作全局方式???对于所有活动???