Notification data is received when the Android application is background or foreground, but notification data is not received when it is terminated.
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
String tit = remoteMessage.getData().get("title");
String body = remoteMessage.getData().get("body");
sendNotification(tit, body);
}
}
private void sendNotification(String body, String title) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("title", title);
intent.putExtra("body", body);
startActivity(intent);
}
}
This is my code. What code should I add if I receive notification data when the app is shut down?