Max Raskin
Max Raskin

Reputation: 1052

Why does an intent gets redelivered when returning to activity from recent apps?

If you launch an activity using Intent with bundled extras, then press home, and the return to that activity from recent apps list.

Then the intent with those bundled extras will be redelivered again.

Anyone knows the reason for this behavior? Will it be wise to use Intent.getFlags() and check whether FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY bits are turned on, and if yes avoid reading that intent?

Thanks

Upvotes: 2

Views: 746

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007369

Anyone knows the reason for this behavior?

That's what is supposed to happen. You are also re-delivered any Bundle you previously populated with onSaveInstanceState(). The objective is for you to present the UI to the user as if you had been around all along.

Will it be wise to use Intent.getFlags() and check whether FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY bits are turned on, and if yes avoid reading that intent?

Generally speaking, I would think that it would be wise to read the Intent and do whatever it calls for. Bear in mind that your activity may be newly created, if Android had terminated your process in between your app moving to the background and the user returning to your app from the recent-tasks list.

If there is state information that you need, to determine whether or not you already did some work of relevance to this operation, store that in the onSaveInstanceState() Bundle, or perhaps derive it from a persistent store.

That being said, you are certainly welcome to look for that flag and do something different in that case, if it is truly needed. Just make sure that you think it through and make sure that this is really what's correct for your circumstance.

Upvotes: 4

Related Questions