Issue
From the MainAcitivty I call the
startActivityForResult(new Intent(this, ActivityB.class), Constant.something);
My Application is on foreground with the ActivityB and my device receive the firebase's notification. The onMessageReceived is called
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification() != null) {
openNewActivity(remoteMessage.getNotification().getBody());
}
}
private void openNewActivity(String messageBody) {
Intent resultIntent = new Intent(this, ActivityC.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle = new Bundle();
bundle.putString(NotificationViewActivity.MESSAGE_EXTRA, messageBody);
resultIntent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , resultIntent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("TESTTTTT")
.setContentText(messageBody)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager ) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1000, builder.build());
}
When I click the firebase's notification when my app is on foreground, the activityC appears. However, when I press back button on my device, it returns to the MainActivity instead of returning the ActivtyB. Therefore, the app calls the onCreate of the MainActivity, it seems relaunch my app. Is there any way to prevent it, I want when press back button, the app returns the the MainActivty (want it calls the onStart-> onResume instead of onCreate->onStart->onResume of MainActivity)
However, when I create the new project with the simple activities. It happened like I want but in my project I is not right. Sorry for my language
Solution
Sorry, above code is right. My teammate put the wrong code at the onBackPressed in activityC. That code calls the MainActivity and set the intent's flags are android.intent.action.MAIN and android.intent.category.LAUNCHER. It makes the app running wrong like I described above
Answered By - Hien Nguyen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.