Can A Stopped Activity Which Belong To A Foreground Task Be Destroyed By The System?
Solution 1:
One scenario in which the foreground task's process is terminated is if, in multi-window mode, your task is in one window, and the user in another window goes into Settings and removes some permission grant. However, at that point, the whole process is gone; Activity B would have been visible in the foreground up to that point, but then is gone.
And, if device undergoes a configuration change while Activity B is in the foreground, then presses BACK or otherwise navigates to Activity A, by default Activity A will be destroyed and recreated... but at that point, Activity B is no longer in the foreground.
And, of course, you can cause Activity A to be destroyed by calling finish()
on it.
Hence, given my interpretation of your question, the answer is "no, if you are not calling finish()
, Activity A will not be destroyed while Activity B is still in the foreground".
Solution 2:
Does it? No. Is it allowed to? Yes.
Android currently does not destroy activities in the backstack without destroying the entire process. However, the docs suggest that it could. As the Android developers have shown no compunction about making changes that cause massive breakage of apps that do not follow the guidelines in the documentation (e.g., the introduction of NetworkOnMainThreadException
) I think it's good practice to rigorously test your apps with Don't Keep Activities on.
Solution 3:
After starting the intent, do a finish(). This will run the onDestroy method for the activity.
Solution 4:
Is it possible (with "don't keep activities" off) that Activity A gets destroyed by the os while Activity B is visible in foreground?
Yes, as long as an Activity
is not in the foreground; Then, there will be a chance to be killed by the OS due to low memory.
During development, the way to simulate this behavior (Your Activity A being killed by OS) is to enable the Don't keep activities in the developer option.
Post a Comment for "Can A Stopped Activity Which Belong To A Foreground Task Be Destroyed By The System?"