如何停止在 Eclipse 下运行的程序?

我找不到停止正在运行的程序的选项(无论是在调试还是发布模式下)。

因此,现在我只需关闭模拟器就可以停止程序(将控制权返回 Eclipse)。

有没有更好的方法来做到这一点? 这样我就不需要关闭(并重新启动)模拟器?

79594 次浏览

In the "Debug" perspective, select the root of the application under "Debug" (where the listing of active threads is) and click the stop button.

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.

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.

Add breakpoint to your code where you want to stop and then run it in Debug mode by pressing F11.

Working for me.

Windows -> Open perspective -> Other... -> DDMS

  1. 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
  2. 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

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

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.

Android Zombies 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?

enter image description here

See picture: 1. Click on DDMS; 2. Select current app; 3. Click on "Stop" enter image description here