简体   繁体   English

通过ADB Shell接受“强制关闭”对话框

[英]Accept 'Force Close' dialog via ADB shell

I'm trying to figure out how (or if it's possible) to accept the 'Force Close' dialog via the adb shell when an Android app crashes with a hard error (specifically out_of_memory). 我试图弄清楚当Android应用因硬错误(特别是out_of_memory)崩溃时,如何(或有可能)通过adb shell接受“强制关闭”对话框。 I'm hoping to basically loop an app with a bash script, so when it crashes I want to start it running again. 我希望基本上是使用bash脚本循环一个应用程序,因此当它崩溃时,我想重新启动它。 The missing step here is that I can't simulate pressing the 'Force Close' button that shows up in the middle of the dialog. 这里缺少的步骤是,我无法模拟按下对话框中间显示的“强制关闭”按钮。

At the same time, the process doesn't seem to actually be running (trying to kill the PID doesn't work), so it's a bit of a weird situation because it seems to have already stopped, but launching it again (via adb shell am ...) just gives me 'current task has been brought to the front'. 同时,该进程似乎并未真正运行(试图杀死PID无效),所以这有点奇怪,因为它似乎已经停止了,但是又重新启动了(通过adb Shell am ...)只是给我“当前任务已被带到最前面”。

Any thoughts would be appreciated! 任何想法将不胜感激!

+1 to DarkXphenomenon for the UncaughtExceptionHandler . UncaughtExceptionHandler +1为DarkXphenomenon

However to kill the process you should use am : 但是,要终止该过程,您应该使用am

am force-stop: force stop everything associated with <PACKAGE>.

am kill: Kill all processes associated with <PACKAGE>.  Only kills.
  processes that are safe to kill -- that is, will not impact the user
  experience.

for example: 例如:

adb shell am force-stop <YOUR.PACKAGE.NAME>

If it is your own app, you can add an UncaughtExceptionHandler and not show the force close dialog. 如果是您自己的应用程序,则可以添加UncaughtExceptionHandler而不显示强制关闭对话框。 If not, the following might work. 如果没有,以下方法可能会起作用。

You can also kill the process from adb. 您也可以从adb中终止该进程。 ( Credit ) 信用

adb shell kill $(adb shell ps | grep YOUR.PACKAGE.NAME | awk '{ print $2 }')

After that, you can use adb shell am ... to respawn the process. 之后,您可以使用adb shell am ...重新生成该过程。

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

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