This question already has answers here:
How to simulate Android killing my process
(15 answers)
Closed 9 years ago.
My application behaves a certain incorrect way after it is killed by the OS while running in the background. In trying to debug this, I've had to basically wait for the OS to do this on every go around - this is very slow, so I was wondering if there was a way of programmatically telling the OS to kill my app.
I have tried android.os.Process.killProcess(android.os.Process.myPid()) and finish() but those don't seem to produce the same behavior as the natural way does.
Does anyone have any suggestions?
You could go on your phone to Settings | Developers Options and set 'Don't keep Activities' checkbox. I'm not sure about exact wording.
This way as soon as any your Activity is in background it immediately gets killed.
You can try setting on Don't Keep Activity feature inside Developer Options.
When you leave each Activity (Because you start another one), Android will kill it (When you are running on low Memory Android behaves this way). Setting this feature on, you will be forced to manage in the proper way the state of each Activity using onSaveInstanceState() and checking por savedInstanceState Bundle in your onCreate()
try the below process:
go to settings->developer options->check the "don't keep activities" checkbox.
Try to use the genymotion that is a excelent Android Emulator. It let you set the battery level and other configurations that can finish your application and do what you want.
Related
The title is pretty self-explanatory. I understand what this developer option does.
What I don't understand are the following points:
Why was that option introduced, in the first place?
After all the changes that the framework has seen throughout the years, is it still useful?
I am eager to know the reasons behind this option.
I believe it's a feature used for debugging purpose.
From the Titanium doc:
Don't keep activities under the Developer Options menu. When this
option is enabled, the Android OS will destroy an activity as soon as
it is stopped. It is intended to help developers debug their apps. For
example, it can simulate the case that Android will kill an activity
in the background due to memory pressure. In normal use, it is not
recommended to turn this option on because this may lead to unexpected
issues on the apps, such as freezes, force closes and reboots.
It sounds like it basically helps testing deterministically how your app behaves when the OS shuts it down due to any reason (out of memory and so on).
So, this replied to point 1. Point 2 is: Yes, I guess :)
EDIT: further references
On SO How to know "Don't keep activities" is enabled in ICS?
an interesting thread about that on androidcentral (reply from MagouyaWare)
The Android framework may destroy your activity any time it's in the background or backstack, and you should write your activities so they behave correctly when this happens. Exactly what that entails varies depending on what the activity does, but it generally includes implementing onSaveInstanceState(...) and restoring any previous state in onCreate(...).
The "don't keep activities" developer option simply changes the framework's behavior so it will always destroy your activity when it goes into the background or backstack. This allows you to test how your activity responds to what is normally a rare occurrence.
A link cited in another answer says:
In normal use, it is not recommended to turn this option on because this may lead to unexpected issues on the apps, such as freezes, force closes and reboots.
This is incorrect. If your activities are written properly, the only effect of having "don't keep activities" turned on should be (possibly) slightly higher battery and CPU usage from constantly saving and restoring persistent state. Any apps that exhibit "unexpected issues" or force closes when this option is on are broken and need to be fixed. As a developer, I habitually leave "don't keep activities" turned on all the time. I've seen a lot of buggy apps, even some of Google's own. But it's never caused a reboot, and I don't think there's any way it could.
I had at least two issues when this was enabled:
1) I was getting an error "Unable to complete previous operation due to low memory" that prevented uploading of any attachment to a website using Chrome, but not with Firefox. I found elsewhere that enabling the "Don't keep activities open" option could have been the problem - it was.
2) I was unable to move files to the SD card. Disabling the "Don't keep activities open" option got round this problem.
Also found elsewhere it can slow things up generally because caching is compromised.
Sometimes apps that I had moved to the SD card suddenly 'greyed out' and became inaccessible. Rebooting solved this, but was becoming an irritation. Too soon to tell if that was another problem caused by this 'feature'.
These problems (and issues with the microphone in Zoom) all started within the last month. I don't know how DKAO ever got enabled, but it's a no-no as far as I'm concerned.
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 question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is it possible to configure an Android install to run a single app?
So, basically, I'm currently working on an android application that is intended for use on dedicated tablets inside of classsrooms. While using this app, we don't want the students to back out and go messing around, ignoring what they're supposed to be doing. Is there a way to:
a) Have an app launch on startup, so there's no initial access to the home screen
b) Lock the app so it can't be backed out of, and will be the only thing to run
The only way to achieve what you're looking for is:
Modify Android at the firmware level
Make your app the homescreen replacement.
Option 2 is considerably easier. Basically, you tell Android that your app is the replacement home screen, and then set it as the default on each device. That way, whenever the device is unlocked, your app will be shown, and pressing the home button will only launch your app. This essentially stops the device from opening up any other apps, unless it is done via notifications, which you can take away by making your app full screen. The only possibility left to leave your app now is via recent apps, or a service that launched apps on a device shake or something. You can get around this by making sure that no other app was launched prior to yours, or clearing the recent apps manually. The service can be gotten around by simple not installing any app that does that.
You can look into the default home screen app, which is open source and available at:
https://android.googlesource.com/platform/packages/apps/Launcher2.git
I've done a fair amount of research on this and the options are not pretty:
1) Write your own Android home screen
This one is involved but seems doable. Theoretically you could choose to write a home screen that only includes a link to your app and doesn't allow any other icons.
Try this link
2) Create you own lock screen
This may give you more control over the device, but the only options historically have been to use unpublished APIs that have been now been changed to disallow this.
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.
HI ,
I need to keep track of installed applications which are used most and least in android device... can anyone help me how to do this programmatically in android...??
My question some thing like , I need to capture the event/Intent which will/may happen when the apllication is launched every time...(like BOOT_COMPLETED will be brodcasted when device booted).
This does not seem possible (unless the launcher/home screen or applications cooperate, e.g. through instrumentation: but that would be strange in production code!). See also this related question.
Edited to add: indiscriminate capture of application launch intents is not AFAIK permitted. Were Android to add such functionality, the security implications would be significant (particularly if interception or modification were allowed!). What you are describing could be (partially) achieved by replacing the home screen.
Some degree of usage information is collected already - from the launcher go to settings - about phone - battery use.
I think this resets every time you go on a charger, and don't know if its visible to ordinary apps.