Closed
Description
onMessageRecieved not working when app is killed. It works perfect in foreground and in background and I can receive Extras in MainActivity. But when app is killed I receive notification and after click on it- Extras == null.
I send only DATA (to, data) notification. What I do wrong?
`
@OverRide
public void onMessageReceived(RemoteMessage remoteMessage) {
Map<String, String> map = remoteMessage.getData();
String message="";
for (Map.Entry<String, String> entry : map.entrySet()) {
message= entry.getValue();
}
sendNotification(message);
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("notification",messageBody);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_name);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notifications_active_black_24dp)
.setContentTitle("MyTitle")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
`
and I've tried to use different flags in intent and pending intent and it not works... (I can't catch intent.putExtra("notification",messageBody); in MainActivity when app is closed.)