views:

55

answers:

3

I have 2 Activities A and B. Now these are my objectives.

  1. When I'm in B and if I press the Home button, the state of the Activity should be saved. (No problem with this.)
  2. When I start B from A after step 1 a new instance of B should be created (i.e) Previous state should be discarded.

But in Step 2 the state of B still prevails. How do I accomplish my objective?

+3  A: 

I think one possible solution woudl be to pass some extra information inside the starting Intent, when you start Activity B from A (like a boolean value). And in the "onStart()" of B, you check if you can find this extra info in the intent (you get it with getIntent()). If it's not present, that means you do reload the activity's previous state. If it is, then you don't reload it.

Scythe
+1  A: 

You don't even need to send a boolean like Scythe suggested. The Bundle savedInstanceState will be null in onCreate for Activity B if Activity A just started it, whereas it will be non-null if you are coming back from a saved state.

Josh