What's the difference between tapping notification when app is on background and terminated

Viewed 63

When tapping the notification with message data through type 3 (open app), the message data are all get from onNewIntent method, is there any difference between when the app is on background and terminated?

If tapping the notification when app is on background, it will reset to the initial screen or keep the previous route path?

2 Answers

When you tap on the notification, it will go to the Intent your specified when creating the notification. There is no difference there. If the app was terminated, it will need to be restarted. In that case any data that was present in memory will have been lost, so anything you need to handle the notification will need to have been written to disk.

When the launch mode of an Activity is set to single task, onNewIntent callback will be invoked when a user clicked on the notification where setContentIntent(pendingIntent) has been set. onCreate won't be called if the app is already running and is visible to the user but onNewIntent will be invoked. onCreate would be called if the app isn't already running and visible to the user. In onNewIntent, the intent passed into the pendingIntent would be delivered to onNewIntent.

Related