简体   繁体   English

如何强制关闭应用

[英]How to force close an app

When my app crashes, it loads again in a random activity instead of being force closed. 当我的应用崩溃时,它会以随机活动的形式再次加载,而不是被强制关闭。

When I call android.os.Process.killProcess(android.os.Process.myPid()) it follows that behaviour too. 当我调用android.os.Process.killProcess(android.os.Process.myPid())它也会遵循该行为。

I just want my app to force close if needed and let the user send me their reports. 我只希望我的应用程序在需要时强制关闭,并让用户向我发送他们的报告。

What should I do to avoid that behaviour? 我应该怎么做才能避免这种行为?

Are you sure it loads some random activity? 您确定它会加载一些随机活动吗? Usually it loads the next activity on top of your app's activity stack. 通常,它将下一个活动加载到您应用程序活动堆栈的顶部。

from https://stackoverflow.com/a/7240460/262462 : 来自https://stackoverflow.com/a/7240460/262462

  1. start first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with FLAG_ACTIVITY_CLEAR_TOP (which will quit all the other activities started after it, which means - all of them). 使用FLAG_ACTIVITY_CLEAR_TOP启动第一个活动(闪屏或当前处于活动堆栈底部的任何活动)(它将退出此活动之后开始的所有其他活动,这意味着-所有这些活动)。 Just make to have this activity in the activity stack (not finish it for some reason in advance). 只需在活动堆栈中进行此活动即可(不要出于某种原因提前完成)。
  2. call finish() on this activity 在此活动上调用finish()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM