Reputation: 934
I have 3 activities associated with 3 xml files.
Activity1 ---> XML1
Activity2 ---> XML2
Activity3 ---> XML3
Activity1 is the main activity that user sees when the application is launched. From this activity, user navigates to Activity2. Then to Activity3.
My question is, should I destroy the activities in the background state for performance tuning?
Upvotes: 0
Views: 40
Reputation: 509
No, you probably shouldn't manually destroy them. Most of the time, Android would intelligently manage the activities that are pushed onto the stack; that is, these pushed back activities won't actually be running (they'll be paused and won't consume CPU cycles, only memory http://developer.android.com/guide/components/activities.html).
If the currently visible activity requires more memory however, Android would know to destroy these paused activities first to free up more memory for the current activity. This way, popping the current activity would only recreate the previous activities if necessary.
Preemptively destroying non-visible activities like this would actually hinder performance since if the user pops the current activity the previous activity would need to be recreated.
To wrap up, the only reason you'd want to do this is if you wanted to use less memory. But like they say, unused memory is wasted memory!
Upvotes: 1
Reputation: 1784
This is not a good practice. The activities remain in the stack since the user may revisit them. If you kill them and the user presses the back button, they will have to restart themselves, which would take some time and would cause unnecessary annoyance to the user. Read more about Tasks and Back Stack here.
Upvotes: 1