[英]Completely terminate activity when onStop happens
As per the Activity lifecycle onCreate happens at the first stage, and in my app I execute some vital code in onCreate. 根据活动生命周期,onCreate发生在第一阶段,在我的应用中,我在onCreate中执行了一些重要的代码。 Problem is if I hit the home button or put the app in background the activity will not be recreated via onCreate, but through onResume.
问题是,如果我按下主页按钮或将应用置于后台,则不会通过onCreate而是通过onResume重新创建活动。
I want that once the onStop method is called the app kills itself so that at the next launch it begins from onCreate. 我希望一旦调用onStop方法,该应用程序就会自行终止,以便在下次启动时从onCreate开始。 If it helps my app is made of only one activity.
如果有帮助,我的应用程序仅由一项活动组成。
(The reason I need this is that copying the necessary code in onResume creates bugs) (我需要这样做的原因是,在onResume中复制必要的代码会产生错误)
You can find a manifest flag android:noHistory
for the activity which provides this behavior. 您可以找到提供此行为的活动的清单标志
android:noHistory
。
Whether or not the activity should be removed from the activity stack and finished (its
finish()
method called) when the user navigates away from it and it's no longer visible on screen —"true"
if it should be finished, and"false"
if not.当用户离开该活动并且在屏幕上不再可见时,是否应该从活动堆栈中删除该活动并完成(调用了
finish()
方法)-如果应结束,则为"true"
,否则为"false"
如果不。 The default value is"false"
.默认值为
"false"
。A value of
"true"
means that the activity will not leave a historical trace.值为
"true"
表示该活动将不会留下历史痕迹。 It will not remain in the activity stack for the task, so the user will not be able to return to it.它不会保留在任务的活动堆栈中,因此用户将无法返回到该任务。 In this case,
onActivityResult()
is never called if you start another activity for a result from this activity.在这种情况下,如果您为该活动的结果启动另一个活动,则永远不会调用
onActivityResult()
。
This might be a little bit more secure than using the life-cycle events for it. 这可能比为其使用生命周期事件更安全。 But keep in mind that any kind of state will be lost afterwards.
但是请记住,此后任何状态都会丢失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.