HOW TO GET BOOLEAN FROM SAVEDINSTANCESTATE ON ORIENTATIOIN CHANGE

Hugh Jackman

Total Post:52

Points:366
Posted by  Hugh Jackman
 822  View(s)
Ratings:
Rate this:

I want to save some boolean variables in Bundle i.e savedInstaceState those i can use after orientation changed .

I tried but always the savedInstanceState result in null

if(savedInstanceState==null){

 savedInstanceState=new Bundle();

 savedInstanceState.putBoolean("isLogoLoaded",true);

 }else{

 savedInstanceState.putBoolean("isLogoLoaded",true);

please provide the better way thanks .

  1. Norman Reedus

    Post:45

    Points:315
    Re: How to get boolean from savedInstancestate on orientatioin change

    Which method are you calling that logic?

    I am guessing that is in onCreate(), onCreate is where you LOAD the savedInstanceState, it is NOT where you SAVE your data. (you can also load it in onRestoreInstanceState)

    You want to save your data in public void onSaveInstanceState(Bundle savedInstanceState) {

     @Override

     public void onSaveInstanceState(Bundle savedInstanceState) {

         super.onSaveInstanceState(savedInstanceState);

         savedInstanceState.putBoolean("isLogoLoaded", true);

     }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!