0

I create a notification with PendingIntent

Intent intent = new Intent(context, SimpleActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, notifId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Starting the SimpleActivity by clicking on this notification on locked screen causes the next activity's lifecycle: onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onStart() -> onResume() or sometimes onCreate() -> onStart() -> onResume() -> onPause() -> onResume(). But when I start SimpleActivity by clicking on notification from unlocked screen then it works fine.

I found some solution in this comment. But it doesn't works for case when activity has a fragments. I found that in some devices in such case fragments may replicate theirs activity's lifecycle so onStart() also called twice in fragments too.

Is this a normal behavior? And is there a way to avoid this so Activity's lifecycle will look like this onCreate() -> onStart() -> onResume()?

0 Answers0