Issue
I've two activities A and B. There si a button BTN in A that does:
Intent myIntent = new Intent(A.this, B.class);
startActivityForResult(myIntent, B_VIEW);
- I click BTN
- Then I click back button that perform a finish() in B.
- Then I quick press the button BTN that opens again B.
The issue is that if the B.onDestroy(), caused by the previous finish() (step 2), has not yet executed, it executes now, so B closes :-(
I want that, if not yet executed, the B.finish() will not fire if I reopen B. How?
Solution
You are better off re-working how you handle this kind of process to begin with.
Your best bet is to package the key data into a bundle in the onSaveInstanceState, and then checking to see if that bundle exists in the onCreate(Bundle) function. Something like this would work (Largely copied from the Android Docs):
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
public void onCreate(Bundle savedInstanceState)
{
if (savedInstanceState==null)
{ //This is the first time starting
mCurrentScore=0;
mCurrentLevel=1;
}
else
{
mCurrentScore=savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel=savedInstanceState.getInt(STATE_Level);
}
}
Answered By - PearsonArtPhoto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.