Navigating through multiple activities
I have 2 Activities A and B. Now these are my objectives.
- When I'm in B and if I press the Home button, the state of the Activity should be saved. (No problem with this.)
- 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?
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.
refer this url
Android; How can I initialise state in one activity, then have another refresh that?
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.
精彩评论