Does a recreated activity remember the original intent started it?

636 views Asked by At

While checking the documentation about using onSaveInstanceState, a question popped up.

Let's say I'm using an app with several activities and now I'm in a specific activity that got started by a previous one. The current activity accepts extra values from the previous one.

If I get a phone call and then navigate back to the activity, it's recreated. But will it remember the original intent of the previous activity that started it? will it be able to get the extra variables from it after recreating itself?

To simplify things:

Activity A starts Activity B (and passing extras to it). Then (while in B) there's an incoming call. I go back to the app so B is recreated- will I still be able to get the extras passed from original the original activity A ?

2

There are 2 answers

0
Anis LOUNIS aka AnixPasBesoin On BEST ANSWER

Yes it will.

One simple way to test this is to rotate the screen when the receiving activity is running, it will be will be destroyed and recreated, and you will notice that you can still get the extras.

Try it and see by your own.

0
queencodemonkey On

Yes, it will be the same intent.

Also just to clarify, when you leave Activity B to answer the call, and go back, Activity B is not necessarily re-created. It is only re-created if the process containing it was killed to reclaim resources. It happens often that in the scenario you describe, Activity B still exists.

For a similar discussion see: Android - Is the intent preserved during activity recreation?