In my case, there was actually a very nasty bug that occurred when you left the app and came back. Somehow I managed to completely sieze up the phone making even the volume and power keys unresponsive. The only way out was to yank the battery! That's a hard lock. But it was actually just a pegged cpu. I could watch the usage spike on the task manager. I know it's my bug, but it's hard to believe that the os would allow a process to runaway like that.
Anyway, long story short, it was better for everyone if my app just quits when the users leaves. Accomplishing that took some research. Many people posted answers that didn't work for me. The one that worked was:
protected void onStop()
{
super.onStop();
//kill this process. It does not reload cleanly. And I think most users appreciate the app leaving memory.
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getPackageName();
am.restartPackage(packageName);
}
and then this would crash and throw up a dialog that my app had crashed and was ok to force quit. So to avoid that dumb message you have to add some permissions to your manifest so people know you can kill your own process.. not thrilled with the whole affair. Anyway, add this:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
to your manifest, and you will have an app that behaves like 99% of the other os's out there.
No comments:
Post a Comment