Reputation: 10298
I like to test my apps with "don't keep activities" checked to make sure everything works in the worst case scenario where Android destroys my stuff. Today I noticed that this setting apparently can (and usually does) cause my entire application to be destroyed after I launch an implicit navigation intent. This is a problem because the original developer put a bunch of important background tasks in an extended Application
instead of using a Service
that Android would be more likely to keep alive when the app is in the background.
With "don't keep activities" checked, my entire app seems to be killed when the navigation activity starts. I no longer see logging from the background tasks, and when I go back to the activity that launched the navigation, it is recreated with a new, uninitialized Application
. I can't simply re-initialize it because the main problem is that the tasks need to keep running while my app is in the background.
I'm not explicitly starting the navigation in a new task:
String encoded = Uri.encode(nextWaypoint);
Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + encoded));
startActivity(navigation);
Is the possibility of my Application
being destroyed as unavoidable as the possibility of my activities being destroyed?
Upvotes: 0
Views: 311
Reputation: 13223
Your Application
will be destroyed when there is no component using the process in which your Application
was started. Since the "don't keep Activities
" option will kill your Activity
when you navigate away from it, and you do not have any other component making use of your process, your Application
is terminated.
Going by what you are describing, your safest bet is to move your tasks to a Service
Upvotes: 1