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?
See picture:
1. Click on DDMS;
2. Select current app;
3. Click on "Stop"
Related
I have found that Android recent app dialog can be disabled by disabling
package com.android.systemui. I want to run my (rooted) device in kiosk mode so it is essential that the recent apps dialog not be shown on long press.
Now, exactly what does com.android.systemui do? I don't need notifications and power indicators and stuff so it is OK if that kind of cosmetic stuff disappears. It is also OK if soft input home buttons disappear because I have replaced them with a software app (Button saviour).
Is it safe to disable com.android.systemui, or do I risk subtle system hangs in certain unclear situations? To put it shortly -is it just another app, or is it absolutely essential to the Android operating system? (I haven't experienced any problems this far!)
Is com.android.systemui available in all Android versions?
If you completely remove SystemUI.apk from the system, your device will hang on start-up and never fully boot again. Tried it before. ;) Framework-res and the system have some dependencies on SystemUI.
The correct, non-invasive way to get rid of SystemUI is to have an application that force-closes it upon BOOT_COMPLETED via am force-stop com.example.systemui or kill <PID>. Depending on device SystemUI restarts itself (not always), if it does you'll have to set a Timer that repeats the kill process. There's an app on Play store that does this, but I can't say for the reliability.
Hope this helps,
I have it disabled on my phone succesfully via removal; gone is the ugly top bar with the notifications and clock.
Drawbacks are that native screenshots won't work nor does the recent apps switcher, but both issues can be fixed via replacements.
Battery life increases slightly due to lower CPU usage.
(I9500 cyanogenmod 11)
I was studying some tutorials on Android programming and I realized that pressing the Home button on the emulator takes me tot he phones Desktop, but my sample that was running at the time only goes to the background and does not get destroyed. However, if I press the return button, the app is destroyed as well. So I am assuming there might be other apps running int he background as well, those which I am not aware of. Is there something in the android emulator resembling the task manager from windows, which shows what apps are currently running on the phone? I don't have a smartphone with me, but I remember seeing something like that on my friend's smartphone a few days ago. It wasn't an external app but was something built into the phone, I could access it by going to Settings or something.
Is there a task manager built into the android emulator, or is there any other way I can see such things through the SDK debugger?
Inside the settings, there is a list of currently running processes.
First , Leaving the activity does not mean the process ends, It is just not invisible . When the Os needs more memory ,it will be recovered.
If you want to have a backup process, you can start a back service.
http://developer.android.com/reference/android/app/Service.html
Here is how I end a process (only works on Android 4.0+).
Instead of pressing home, press recent and swipe away the process you want to end. Then press home (or back).
You can also use this to close those nasty apps that prevent you from closing them by not allowing back button to work on their main screens.
This is much quicker than having to go to settings, etc.
This might be a bit of a stupid question but my application seems to stay running even after I have stopped it. I close it by holding down the home key and dragging the application off to the left. However, I still see logcat output, it only stops if I go to settings-->Apps-->Running Apps and stop it this way. Is this a bug in my application or is this expected android behavior?
This is expected . Android behaviour
Unlike many other Operating Systems, Android does by default not have a dedicated button to close an application manually. This is because Android is designed to manage the running applications itself and close them as needed.
By design, Android handles the memory and time assigned to applications. This ensures that applications that are left opened do not cause the smartphone to slow down or run out of memory.
When pressing Home button, your app will go to the background and Android O/S will close it when low on memory. If not and you open the application again, it resumed where you left off.
Unless you specifically create a method in your application that closes (finishes) your app.
I have been seeing errors come back from my application that it's force closing after the system stop's it and the user bring it back to the front at a later time.
I have some idea's as to what is causing this but I would like to be able to reproduce this error before attempting to fix it.
Does anyone know a way to get the android system to behave like it needs the memory my application is using and close it so I can easily and continually reproduce this error?
Using the Dev Tools app on your emulator, you can have the OS destroy an application as soon as it's stopped.
From the documentation:
Immediately destroy activities
Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). This is very useful for
testing the onSaveInstanceState(Bundle) / onCreate(android.os.Bundle)
code path, which would otherwise be difficult to force. Choosing this
option will probably reveal a number of problems in your application
due to not saving state. For more information about saving an
activity's state, see the Activities document.
You can find this under Development Settings once you're in the Dev Tools app. So, when running your application, you could just switch to another application (like clicking on the emulator's hard phone button), and return to yours to test the destroy/create process.
If you are using Eclipse or DDMS you can select your app in the process list and hit the stop button. This should close your app.
I am going through the Android tutorials and at some point an app won't load. The last message on the console is "Installing RelativeLayout.apk..." and it just stays there forever, instead of going on to the "Success" message. Visually, what is happening on the emulator is that it starts with the "A N D R O I D" phase, goes on to the chrome "android" phase, goes on to the home page, and then the little animating battery icon stops moving. After that we go back to the chrome "android" and just stay there forever. Quitting the emulator and rerunning the app doesn't help.
Looking at the log, using the adb tool with logcat, at one point the log lists service after service that died. This occurs right after this log message:
D/Zygote ( 32): Process 59 terminated by signal (11)
When I run adb logcat and have the emulator window visible at the same time, I can see that the battery icon stops animating just about when this message appears. No idea what this means.
I can fix the problem by going to Window --> Android SDK and AVD Manager which has a list of the AVD's if you click on "Virtual Devices" on the left. What I discovered to work is to quit the emulator, then in this window to select the AVD I'm trying to use, click "Start..." on the right, then in the Launch Options box that comes up, check Wipe user data, then hit Launch. The emulator will run until the home page shows up, then I can run my tutorial just fine.
What's causing the problem? What am I doing wrong? I blogged about this in my Into Apps blog and I'd like to be able to post the solution to the mystery as well.
What is your app doing? specifically, are you doing any CPU intensive work that could be stalling out the emulator? If you are, it could be you have a service that doesn't shut down properly, or a run away thread.
If not, i would say just uninstall your SDK and everything to do with the emulator and reinstall a fresh copy. Could just be that there is something screwy with your integration.