Reputation: 3665
My application consist (for example) of 3 activity: Activity1, Activity2, Activity3. Every activity has a unique background image on all its main layout declared in an XML File. From Activity1 user goes to Activity2 and next to Activity3 so first 2 get pushed into the stack. The problem is that first 2 activities occupy too much memory, and in Activity3 I have OOM exception sometimes. I have found this answer about reason of this behavior - https://stackoverflow.com/a/4836241/1159507 Before this, I believed that when activity goes to stack it releases all memory. I believe that the same behavior with fragments stack. So my question is - how to relese memory when activity or fragment goes to stack and keep responsible UI on back press?
Upvotes: 1
Views: 1488
Reputation: 3357
Activity's resources (which are not released in onPause, onStop, ...) do not get released when the Activity goes to the background.
Upvotes: 1
Reputation: 5176
You can save all your huge memory consuming objects (Ex: Large Images in your case) to local storage in onStop()
of your first activity and when user presses back you can load them in onStart()
of your first activity.
Upvotes: 1