简体   繁体   中英

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). 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!

+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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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