0

I have an application that reuses an Activity an unknown number of times. It runs

a> b1||c1 > b2|| c2 > ...

If I go a > b1 > b2 > b1, my app still shows the b1 list on the screen, but if I click on it, it takes me to the corresponding b2 activity. the arrayList that i use to hold the data for b needs to be restored for the correct instance of b.

Ive been reading over http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle but I dont think that onPause and onResume will work since Im using the same activity again.

r2DoesInc
  • 3,759
  • 3
  • 29
  • 60

1 Answers1

0

It all depends on the way you are moving between activities.

When you press back or you do finish() you destroy your activity. I belive in this case you are doing finish() on b2 and you return to b1.

Think on Activities like a stack that contains instances of your activities. You can have several instances of the same activity in your stack.

When you are on a and you go to b1 your stack stays like this:

b1
a

When you go to b2, your stack gets like this

b2
b1
a

Then if you do another startActivity() for b1 you get

b1
b2
b1
a

However, if you do finish() or you press back you actually destroy b2 and you get back to the first instance you got from b1. Remember: In the stack you have instances of activities that can hold different data.

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
  • when I press back in activity b2 though, it only displays the ui list from b1. the actual data is still the data from b2. say i have a list on b1 with 12345. I open b2 which displays 67890. hit back and displayed is 12345. if i select a list entry to log the data at that point, say 3, it logs 8. the actual data from b1 isnt being restored. – r2DoesInc Apr 02 '12 at 20:16
  • I have no ideia how you are organizing your data. However, if you press back the top activity on the stack dies and the `onResume()` on the next activity in the stack is called. Please check your `onResume()` to see what are you doing. Also check if you are doing changes in the structure that provides the info or the adapter. And at last please check if your info is static (and therefore can be shared by all activities) or if your info is local (in your activity). – Tiago Almeida Apr 02 '12 at 20:53