Accept 'Force Close' dialog via ADB shell

2019-05-29 08:07发布

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). I'm hoping to basically loop an app with a bash script, so when it crashes I want to start it running again. 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'.

Any thoughts would be appreciated!

标签: android adb
2条回答
劳资没心,怎么记你
2楼-- · 2019-05-29 08:20

If it is your own app, you can add an UncaughtExceptionHandler and not show the force close dialog. If not, the following might work.

You can also kill the process from 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.

查看更多
【Aperson】
3楼-- · 2019-05-29 08:40

+1 to DarkXphenomenon for the UncaughtExceptionHandler.

However to kill the process you should use 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>
查看更多
登录 后发表回答