When I press back in my activity , it calls the onSaveInstanceState()
and saves the "bundle savedInstanceState" which is right.
But I want to destroy it or set it to null only when I press back button or on destroying activity
I just need onSaveInstanceState()
inside my activity for configuration changes.
I think I need to use onBackPressed()
but what should I put in it ???
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
}
Edit :
Lets say I have an activity contains a list when I click an item on the list the activity I mentioned above will start.
My second activity is a master/detail flow activity, When I click an item on the list of this activity it will update the detail's fragment (which is a viewpager here ) and it will save the current choice of the list.
Now when I press back button on second activity, it goes back to the list activity, again if I click a list item it will goes to second activity with the choice I had before pressing back. ( it's kinda save the choice through back stack )
But I noticed it has nothing to do with savedinstancestate, My second activity will not destroy through back button it will detach and then attach like fragments.
I want to completely destroy second activity when the back button is pressed.
Edit 2 :
When i even close my application through back button and launch it again, and then go to second activity, I see my last state and the item I clicked. ( I used setChoiceMod(...single) on the list )
Thanks for your help.
I noticed that the variables I defined in the second activity, is saving their values (that I changed in activity) through back stack and even closing application wouldn't delete them.
The variables :
static int mcurchoice ;
static int mcurtab ;
I solved my problem by setting them to 0 in onBackPressed()
method :
mcurchoice = 0;
mcurtab = 0;
can someone explain in comments how they will save their values through activity's destroy .?