Issue
As it is said in the Dev Guide Activities could be restored after "the App process is killed" and "User navigates to the Activity". First of all, I have never seen such thing happened. It doesn't seem that I can "navigates back" to an Activity when its process is killed, the Activity is simply gone from the stack after the process is gone.
If such thing is to happen, how exactly it will happen?
And I saw a weird but good thing is that:
There is one Activity A1
which starts Activity A2
of another App. Now A2
is the foreground activity. When memory gets low, at least on emulators(where I can easily eat up the RAM), A2
will be killed instead of A1
.
What I fear is something like this for example:
My App have two Activities on the stack, and we call them A0
and A1
. And A1
, again, launched Activity A2
of another App. When A0
was about to launch A1
, it gives A1
a reference to a data object D
. Now if process for A0
and A1
is killed while A2 is in foreground, D
is lost, too. When A2 has finished, it seems at least A1
will need to be restored. And thus A1
will have to handle the restoration of D
. And what's more A1 will have to find a way to tell the still-dead A0
the reference to the restored D
. This is complicate or I have walked the wrong way?
Solution
The system will do anything it can to keep the foreground app alive.
The Intent
that was used to launch the activity is saved by the system when the process is about to be killed.
This way, once the user returns into the app which has been killed, then the app is restored and the same Intent
is fired to launch the activity including all the extras that it might have.
This means any data you pass into the Intent
to launch an activity, will still exist when the activity is restored.
You might not notice it, but Android does kill and recreate process on a day-to-day usage, and thats the whole point of seamless multitasking the platform offers.
You should always test your app with the "Don't Keep Activities" option on in the "Development" settings.
Answered By - dnkoutso
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.