Can a system block a suspended activity that belongs to a foreground task?

From the white paper :

When action A starts action B, action A stops, but the system retains its state (for example, the scroll position and the entered text in the form). If the user presses the back button during action "B", Activity A resumes with the restored state.

Activity A is not destroyed at this stage. However, if one of the developer’s parameters does not contain an action, action A will be destroyed, and when the user clicks a button in action B, operation A will be activated.

Also from an official document :

Note. Several tasks can be held in the background at once. However, if the user starts many background tasks at the same time, the system may begin to destroy background actions in order to restore memory, as a result of which activity states will be lost.

As far as I know, “do not continue actions” is useful because it helps to recreate a situation where os kills your application process when it is in the background.

Is it possible (with the activity turned off, it does not turn off) that activity A is destroyed by os, and activity B is visible in the foreground?

0
android android-activity
May 31 '17 at 14:01
source share
4 answers

One scenario in which the foreground task process ends is that in multi-window mode, your task is in one window, and the user in another window goes into settings and removes some resolution. However, at this moment the whole process disappeared; Activity B would be visible in the foreground to this point, but then disappeared.

And, if the device undergoes a configuration change while the action B is in the foreground, then presses BACK or, otherwise, goes to Activity A, by default, Activity A will be destroyed and recreated ... but at that moment Activity B is not longer in the foreground.

And, of course, you can force Activity A to be destroyed by calling finish() on it.

Therefore, given my interpretation of your question, the answer is "no, if you do not call finish() , action A will not be destroyed, and action B is still in the foreground."

+1
May 31 '17 at 14:07
source share

Is it possible (with the activity not to “continue”) that action A gets destroyed by os, and activity B is visible in the foreground?

Yes, if the Activity not in the foreground; Then it will be possible to be killed by the OS due to low memory.

During development, a way to simulate this behavior (your activity A, killed by the OS) should include the Do not perform actions in the developer option.

+1
May 31 '17 at 2:12 pm
source share

It? No. Is it allowed? Yes.

Android does not currently destroy backstack actions without destroying the entire process. However, the documents suggest that this is possible. Since Android developers did not show any failures in making changes that cause massive application crashes that do not meet the recommendations in the documentation (e.g. introducing NetworkOnMainThreadException ), I believe that it is good practice to thoroughly check your applications with Do not Keep working.

+1
Jul 21 '17 at 15:54
source share

After running the intent, finish (). This will launch the onDestroy method for activity.

0
May 31 '17 at 14:06
source share



All Articles