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.
Related
I have crashes occurring in my app when the drops in the LRU-application list within androids OS (See http://developer.android.com/guide/components/processes-and-threads.html#Lifecycle). This is due savedInstanceStates not being handled properly. It's really painful and time consuming to constantly have to open my app and then open like ten other applications just to mimic these errors and verify my fixes.
Is there a quick way to mimic this via code?
The way I test those cases is go to Settings > Developer Options. Scroll to the very bottom and enable Don't keep activities. Also, set the Background process limit to No background processes.
Open your app and hit the home button once you are in the activity you want to test and then bring it back from the Recent Apps list.
Hope this helps.
I want to observe an app's process being killed automatically (when the app's activity is stopped and other processes need the memory). I'm keeping my eye on Android Studio's Devices pane while I launch other processes, but this doesn't seem to kill my dormant activity. Is there a way to insure that this happens (and is observable)? (I know, . . . Why would I ever want to do this? It's because I'm teaching Android and I want to illustrate this concept.)
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 a Phonegap and JQM app.
Problem is, if I switch to another app and then back to my app, App is completely reloaded and start again.
Is posible this disable?
Thanks for any advice.
This is happening because there is a lack of memory for the app to run. So as soon as u go to home the app dies and on opening again it reloads the app from the start. To confirm that this is indeed happening i would suggest that you close all running apps on your phone and then run your app. Im sure it would run properly even after switching to home screen and coming back.I don't think its possible to get around this behavior. Design your app so that it has a small startup time so that its usable even on phones with less ram where such problems would come.