106

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?

Jonathan Soifer
  • 2,715
  • 6
  • 27
  • 50
Android Eve
  • 14,864
  • 26
  • 71
  • 96

9 Answers9

112

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.

Pico Riley
  • 113
  • 5
Varun
  • 33,833
  • 4
  • 49
  • 42
  • 1
    Adding another way I just discovered: in the emulator select Settings > Applications > Manage applications > (select app) > Force stop. – Android Eve Feb 23 '11 at 16:32
  • Ya. that is another way, but it takes time to reach there, unless u have that in the background. :) – Varun Feb 23 '11 at 16:47
  • 11
    a Stop button like in Visual Studio would be oh so nice. ugh. – Ian Davis Jul 19 '12 at 14:27
  • Just started the app right after the project creation and when clicking stop button it did not kill the process but fired a `RemoteException sending setActive(false) notification` in the _logCat viewport_ – Stphane May 17 '14 at 22:13
  • That kills the process, not a stop. Stopping is part of the Android lifecycle and onStop() actvity method must be called. That device window just kills the app VM at the OS level, and onStop() is not called. Kill is not Stop. The Android lifecycle must take precedence when defining what Stop means. – Dominic Cerisano Jan 22 '15 at 12:53
  • The stop button appears disabled in the devices window in eclipse (Juno) for both AVD as well as actual device – Martin Feb 05 '16 at 12:33
77

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

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
GeekityGeek
  • 771
  • 5
  • 2
  • +1. Great !, and if I want it to run it again, I just start it from the device again, and it works perfect. – Francisco Corrales Morales May 05 '14 at 16:51
  • One more step, find your packageID on the list. At first I was put off by that, but then I was like "Oh cool! I can see everything." Nice to see what Android has under its hood (note: I'm using Genymotion simulator, maybe emulator is what you say, I just can't stand waiting for it to run) – Stephen J Jun 07 '14 at 07:08
  • This violates the Android app lifecycle and can lead to ungraceful exits resulting in the inability to restart the app and forcing device reboot to clear the problem. – Dominic Cerisano Jan 22 '15 at 12:58
13

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.

DJC
  • 3,243
  • 3
  • 27
  • 31
  • This is a great insight. Thank you. +1 – Android Eve Feb 11 '11 at 18:43
  • 1
    @Eve .. my pleasure. For gory details, check http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon – DJC Feb 11 '11 at 18:47
  • 4
    Well, maybe. But this doesn't really answer the question. In my case, I am playing around with the AudioTrack class and generating a stream of sounds. It gets really annoying to listen to that sine wave all the time. I have to go to DDMS, hunt down the right thread, select it, then find the STOP icon. Very lame. – Vagrant Mar 02 '11 at 05:58
  • 2
    How can you reset the state of your program without stopping? – Erik Engheim Aug 01 '12 at 13:35
  • I noticed with the Emulator, it won't run your program again until after a few minutes or so (probably because it is still running). It comes in handy to finish earlier, when you need to make a small edit, then quickly check it in the Emulator. And often, you are making several small edits, so being able to stop the running app and reload it to check quickly saves a lot of time. – Azurespot Mar 20 '14 at 01:19
  • Your answer doesn't work on my setup, attempting to run a project on a device when there's already one running returns error "Starting: Intent; AppActivity / Warning: Activity not started, its current task has been brought to the front" – redux Aug 31 '14 at 14:59
  • @DJC, Why stop? Because you don't want it to run. Imagine running an app that pings a server every x seconds `while(true)`. – Pacerier Nov 17 '14 at 08:40
12

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

Chris Thompson
  • 35,167
  • 12
  • 80
  • 109
  • thank you too. I understood your instructions only after reading @varun's. +1 – Android Eve Feb 11 '11 at 18:42
  • @Android Eve, ah, well I'm glad it helped. Sorry it wasn't clear enough! – Chris Thompson Feb 11 '11 at 18:43
  • That's OK. I am totally disoriented in regard to Android development, despite (and perhaps because of) many years of development on many other platforms. – Android Eve Feb 11 '11 at 18:45
  • Yes, this is by far the easiest solution. (In fact, should prob be the accepted answer). The Stop button is only disabled when a thread is highlighted instead of the top [Android Application] entry. – Colin Nov 12 '14 at 16:09
7

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

Zain Ali
  • 15,535
  • 14
  • 95
  • 108
2

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.

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
0

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

Dominic Cerisano
  • 3,522
  • 1
  • 31
  • 44
0

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

Eugene Bosikov
  • 840
  • 10
  • 12
  • I do this and app stop debuging. but there is to case: 1- disconect device from usb, run app then when app face error it close and after that on every run bring up debuging form and wait for usb cable to connect or backbutton press. 2- device connect to usb and app run (Ctrl+f11) then, automatically app run under debug mode. To solve this, I created a new project, and one by one copy/pasted files to new project, but the same thing happen again. Now any help? – Ahmad Ebrahimi Apr 20 '15 at 22:13
0

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

salman khalid
  • 4,884
  • 4
  • 27
  • 33