系统可以销毁属于前台任务的已停止活动吗? [英] Can a stopped Activity which belong to a foreground task be destroyed by the system?

查看:94
本文介绍了系统可以销毁属于前台任务的已停止活动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自官方文档:

活动A启动活动B时,活动A停止,但活动 系统保留其状态(例如滚动位置和输入的文本 成表格).如果用户在活动B中按下返回"按钮, 活动A恢复其状态.

When Activity A starts Activity B, Activity A is stopped, but the system retains its state (such as scroll position and text entered into forms). If the user presses the Back button while in Activity B, Activity A resumes with its state restored.

活动A目前尚未销毁.但是,如果设置了一组开发人员选项不保留活动",则活动A将被销毁,并且当用户在活动B中按下后退按钮时,将重新创建活动A.

Activity A is not destroyed at this point. However, if one set developers option "don't keep activities" on, Activity A will be destroyed and when the user press back button in Activity B, Activity A will be recreated.

也来自官方文档:

注意:可以一次在后台执行多个任务.然而, 如果用户同时运行许多后台任务,则 系统可能会开始破坏后台活动,以便 恢复内存,导致活动状态丢失.

Note: Multiple tasks can be held in the background at once. However, if the user is running many background tasks at the same time, the system might begin destroying background activities in order to recover memory, causing the activity states to be lost.

据我所知,不要保留活动"很有用,因为它有助于重现操作系统在后台时杀死应用程序进程的情况.

As far as I know, "don't keep activities" is useful because it helps recreate the situation in which the os kills your app process when it's in background.

在前景中可见活动B的情况下,活动A是否有可能(在不让活动保持关闭状态"的情况下)被操作系统破坏?

Is it possible (with "don't keep activities" off) that Activity A gets destroyed by the os while Activity B is visible in foreground?

推荐答案

在多窗口模式下,如果前台任务的进程终止,则该场景是如果您的任务在一个窗口中,而用户在另一个窗口中进入设置"并删除一些权限授予.但是,到那时,整个过程已经一去不复返了.到那时为止,活动B在前景中是可见的,但随后消失了.

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.

并且,如果在活动B处于前台时设备进行了配置更改,则按BACK或导航到活动A,默认情况下,活动A将被销毁并重新创建...但是到那时,活动B为否前景更长.

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.

当然,可以通过在其上调用finish()来破坏活动A.

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

因此,按照我对您的问题的解释,答案是不,如果您不拨打finish(),则活动B仍在前台时,活动A将不会被破坏".

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".

这篇关于系统可以销毁属于前台任务的已停止活动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆