为什么有时应用程序会在killProcess上重新启动? [英] Why would Application sometimes restart on killProcess?

查看:129
本文介绍了为什么有时应用程序会在killProcess上重新启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,通过调用以下命令退出我的应用程序:

Ordinarily, exiting my application by calling:

android.os.Process.killProcess(android.os.Process.myPid());

表现出色,没有发生意外.

performs well without incident.

但是每隔一段时间,应用程序将再次重新启动(退出后!).

But every once in a while, the application will restart again (after exiting!).

相关的日志片段显示:

.631: I/Process(15495): Sending signal. PID: 15495 SIG: 9
.641: W/AudioFlinger(121): write blocked for 252 msecs, 1279 delayed writes, thread 0xdc18
.651: I/ActivityManager(164): Process com.ef.myapp (pid 15495) has died.
.651: I/WindowManager(164): WIN DEATH: Window{463659e8 com.ef.myapp/com.ef.myapp.MainActivity paused=false}
.661: I/AudioService(164):  AudioFocus  abandonAudioFocus() from android.media.AudioManager@460b2b98
.701: I/ActivityManager(164): Start proc com.ef.myapp for activity com.ef.myapp/.MainActivity: pid=15589 uid=10077 gids={3003}

我知道,通过Android操作系统的设计, killProcess()会停止立即处理 ,而不会给应用提供任何方式阻止或阻止它或为它做准备.

I know that, by the design of the Android OS, killProcess() isn't the proper way to terminate an application. This is because killProcess() stops the process immediately without giving any way or chance for the app to prevent it or prepare for it.

我知道,当我致电 finish() ,应用程序堆栈仅被推送到后台(并且仍然存在于内存中). Android本身会决定何时关闭应用程序(即,从内存中删除其实例),通常是在应用程序变为最长时间未使用的最旧的应用程序"时才执行此操作.如果它确实是最后一个,它的行为实际上是可以预测的.

I know that when I call finish(), the application stack is just pushed to the background (and still exists in the memory). Android itself decides when to close the application (i.e. remove its instance from the memory) and generally this is done when the application becomes "the oldest not used for the longest time". Its behavior is actually more predictable if it's really the last one.

问题在于 finish()只会停止并销毁其被调用的活动.它不会阻止应用程序或其他活动产生的其他活动.因此,为了便于测试和测试,在开发过程中进行调试,我使用的是 killProcess()作为便捷的快捷方式.

The problem is that finish() only stops and destroys the activity for which it was called. It doesn't stop other activities spawned by the application or other activities. So, for ease of test & debug during development, I am using killProcess() as a convenient shortcut.

但是现在我看到这有副作用,应用程序有时在杀死自己后立即重新启动-所有在30毫秒之内.

But now I see that this has the side effect of the application sometimes restarting immediately after killing itself -- all within 30 milliseconds.

一种直接的解决方案是遍历所有应用程序的活动和

A straightforward solution would be to iterate through all application's activities and finish() them. But before proceeding with this, I am dying to understand what in the Android OS makes an application resurrect itself.

为什么,Android将使被终止的应用程序重新启动?

Why would Android make a killed Application restart?

为什么不一致? (即有时)

And why inconsistently? (i.e. sometimes)

推荐答案

从安装程序,网络浏览器以及通过IDE(IntelliJ ,Eclipse等).请尝试不启动就安装您的应用,然后从可用应用列表中启动它,看看问题是否消失了.请参阅与该问题相关的很久以前提交的以下问题:

There is a known bug in the way applications get started the first time from the installer, web-browser and via IDE (IntelliJ, Eclipse, etc.). Please try to install your app without starting it and then start it from the list of available applications and see if the problem goes away. See these issues filed long ago related to the problem:

http://code.google.com/p/android/issues/detail?id = 2373

http://code.google.com/p/android/issues/detail?id = 26658

这篇关于为什么有时应用程序会在killProcess上重新启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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