I can’t find an option to stop a running program (whether in debug or release mode).
So for now, I stop the program (returning control to Eclipse) simply by closing the emulator.
Is there a better way of doing this? Such that I don’t need to close (and restart) the emulator?
I understand you want to stop your app on the emulator. For this you can open up the devices window (in the debug perspective), select the process and then press the stop button on the same window.
Those who find it tedious switching between perspectives to stop the program (like I did), you can view the devices windows in your current perspective by selecting
Windows > Show View > Other… > Android > Devices
Keep in mind that on Android, programs generally only ‘stop’ if you finish() or the system destroys them when memory is required. Why stop at all? You do not need to stop to fix/re-install/re-test, for example.
In the “Debug” perspective, select the root of the application under “Debug” (where the listing of active threads is) and click the stop button.
Working for me.
Windows -> Open perspective -> Other… -> DDMS
- In the Android view, on the left windows, you can see “Devices”. There should be a list of applications that is running now (Emulator or physical devices).
Click on the application you want to close. Normally the name is the name of the package + the name of the application
- Now click on the symbol of “Stop”.
To come back to the normal view, you just have to press on the Java button on the top right side.
You can also do it pressing:
Windows -> Open perspective -> Other… -> Java
this answer doesn’t deal with Eclipse, but since this question comes up in a Google search for stopping a running Android program, I’d like to offer a command-line method. run
adb shell, find the PID of the process you want to kill with
ps, for example mine was:
u0_a46 2097 37 175520 19912 ffffffff 40037ebc S net.unternet.bleah.blarg
so then just
kill 2097 and you should see the main screen show up again.
Add breakpoint to your code where you want to stop and then run it in Debug mode by pressing F11.
Figure 1 – Many Zombies were killed during the research of this Answer
Killing an Android application Java VM process at the OS level is not recommended. Unfortunately, this is exactly what the eclipse device window “stop” does, as does System.exit() and the shell “kill” command.
This subverts the normal app life-cycle methods such as onStop(), onDestroy(), and finalize().
Many apps require these methods for graceful exit (for ex. if they use system objects like Sensor, MediaPlayer, Equalizer, Visualizer, etc).
These system objects hang around with zombie death grips on system resources if release() is not called explicitly during these life-cycle methods. See fig. 1 above. This can prevent an app from restarting, and even require a reboot. That is the ungraceful aspect.
The only solution is to make sure you always exit your app cleanly with a call to onStop() or onDestroy() or at least finalize(). The debugger does this, as does the OS on shutdown.
You can set your app to trap SIG_HUP events in order to force a graceful exit from the command line.
The only time you would kill the app VM is in ANR (already a zombie) state. ANRs must be fixed. Never deploy an app that can enter this state. It is extremely rude.
You can use Google analytics and the Play Store to monitor for these in deployment. You don’t want angry users giving single star ANR reviews after having to reboot due to your zombie application. Very bad.
Remember that Android is Linux: treat it like a real OS, and respect the app life-cycle otherwise you shall surely face the dreaded Zombie Apocalypse.
PS: If you don’t like the Zombie analogy, how about Fantasia?
1. Click on DDMS;
2. Select current app;
3. Click on “Stop”