Search code examples
androidandroid-activityandroid-push-notification

Different call sequence of the Activity lifecycle callbacks while opening app from the push


I'm seeing a strange behavior while open app from the push notification.
There are 2 cases:
1) the app is in the background and device is unlocked;
2) the app is in the background and device is locked.

When device receives push notification I click on it, my app starts (device screen is being unlocked if needed) and I see the following sequence of the Activity lifecycle callbacks:
1) in the 1st case - onResume is called once;
2) in the 2nd case - onResume -> onPause -> onResume.

I'm interested in 2nd case. The second onResume's call I'm understanding.

Why Android calls onPause's callback?
Is it default behavior or problem in my app settings (for example specific launchMode in my Activity)?
Anybody can help me understand the 2nd case and how to avoid it?


Solution

  • There are many related questions on Stackoverflow about onResume() and onPause() being called multiple times in combination with use of the lock screen. This seems to be a common problem. In general, onPause() and onResume() can be called many times, also in quick succession and your app needs to be robust enough to handle that.

    See: