0

Is it possible to reuse an activity without destroying it? For example, after I press BACK button, the activity will disappear and the app returns to the previous activity. But that disappeared activity is still in memory and can be fast displayed without re-creating it.

This is the reason why I have such an idea: I use an activity which was written by others. I found there were some memory leaks but I couldn't find them because I have no source code. So I want to find a workaround.

flypen
  • 2,515
  • 4
  • 34
  • 51

2 Answers2

1

Its possible if you don't kill your activity:

open 1, 2, 3 activities
1 > 2 > 3  

back to #2 // call startActivity for 2, don't call finish() in 3
1 > 2

open #4 activity
1 > 2 > 4

back to #2
1 > 2

restore #3 activity // call startActivity for 3 with intent as Intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_To_FRONT);
1 > 2 > 3

Here you will get as it is copy of activity 3 as you left it.

Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
1

Check this Link

You should override the back button and bring the Activity to Foreground without actually finishing it.

Community
  • 1
  • 1
Sudhaker
  • 785
  • 1
  • 6
  • 13