Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top