简体   繁体   English

Android强制停止回调应用程序?

[英]Android force Stop callback to application?

If an app is forced stop by following the steps Settings->Application->ManageApplications -> --> Force Stop , Does android call the onDestroy of the Activity or the Application ? 如果通过以下步骤强制停止应用程序设置 - >应用程序 - >管理应用程序 - > - >强制停止,android是否会调用活动或应用程序的onDestroy? (If not , Is there any way to know if the application has died due to a force Stop triggered by the User ) . (如果没有,有没有办法知道应用程序是否因用户触发的强制停止而死亡)。

Force stopping the app will kill the entire process (ie with Process.killProcess(int pid) ). 强制停止应用程序将终止整个过程(即使用Process.killProcess(int pid) )。 All resources associated with the application will be removed and freed by the kernel. 与应用程序关联的所有资源都将被内核删除并释放。 So no, there is no way that you can intercept this action. 所以不,你无法拦截这个动作。

When you release your application on the market, the developer console will provide you with stats regarding force closes, crashes, etc. (if that is why you are asking). 当您在市场上发布应用程序时,开发人员控制台将为您提供有关强制关闭,崩溃等的统计信息(如果这就是您要求的原因)。

In short, no, onDestroy() is not called, and you can't do this. 简而言之,不, onDestroy()不会被调用,你不能这样做。 Android doesn't support it. Android不支持它。

A more extended answer... 一个更广泛的答案......

onDestroy() does not appear to be called in this scenario. 在这种情况下似乎没有调用onDestroy() I tested this by attempting to have it Toast me before calling super.onDestroy, but the Toast message never showed up. 我试图通过把它测试了这个Toast调用super.onDestroy之前我,但Toast的消息一直没有露面。 (And according to this post , onDestroy() is really unreliable and won't be called often, if at all, on phones, whereas it may be called on an emulator - so be aware of that). (根据这篇文章onDestroy()实际上是不可靠的,如果有的话,不会经常调用电话,而可能会在模拟器上调用 - 所以要注意这一点)。 Instead killProcess() is called, and we cannot intercept that. 而是killProcess() ,我们无法拦截它。

In addition, according to the accepted answer in this post , it appears we can't even catch and perform tasks after a user-controlled force stop. 另外,根据这篇文章中接受的答案,看来在用户控制的力停止后我们甚至无法捕捉和执行任务。

No. This isn't really possible. 不,这真的不可能。 I haven't looked at the Android code in question, but I would imagine that "force stop" is just calling kill on the process ID of your app. 我没有看过有问题的Android代码,但我认为“强制停止”只是在你的应用程序的进程ID上调用kill So the only way you could intercept that is if you could trap signals, which I don't think Android allows. 因此,你可以拦截的唯一方法是,如果你可以捕获信号,我认为Android不允许。

If you were rooted, you could possibly do this, but not in any standard way. 如果你扎根了,你可能会这样做,但不是以任何标准的方式。

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

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