我有一个BroadcastReceiver,每当他们收到Firebase通知时,我都会尝试更新MainActivity上某物的颜色。但是,永远不会调用方法onReceive。我不知道怎么了。
MainActivity中的方法:
@Override
public void onStart() {
super.onStart();
LocalBroadcastManager.getInstance(this).registerReceiver((receiver),
new IntentFilter("MyFilter"));
}
@Override
public void onStop() {
super.onStop();
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
}
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("entereeeeed", "emntereedd");
bv.setBadge(true);
String Action = intent.getStringExtra("Action");
switch (Action) {
case "updatedata":
try {
boolean value = intent.getBooleanExtra("bv", false);
//bv.setBadge(value);
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
break;
}
}
};
NotificationService:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
LocalBroadcastManager broadcaster = LocalBroadcastManager.getInstance(getBaseContext());
Intent intent = new Intent("MyFilter");
intent.putExtra("bv", true);
intent.putExtra("Action", "updatedata");
broadcaster.sendBroadcast(intent);
谢谢!