android - how to use onSavedInstance method to prevent data loss while changing to landscape mode -


i making sample of twitter integration ,i fetching user information on click of button. data coming on screen working fine portrait modeb changed landscape mode ,data loss.

how solve issue, dont know how use onsavedinstance method solve problem. please help

you need override android default methods onsaveinstancestate , onrestoreinstancestate check example.

 @override     public void onsaveinstancestate(bundle savedinstancestate) {         // save user's current game state         savedinstancestate.putint(state_score, mcurrentscore);         savedinstancestate.putint(state_level, mcurrentlevel);          // call superclass can save view hierarchy state         super.onsaveinstancestate(savedinstancestate);     }      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate); // call superclass first          // check whether we're recreating destroyed instance         if (savedinstancestate != null) {             // restore value of members saved state             mcurrentscore = savedinstancestate.getint(state_score);             mcurrentlevel = savedinstancestate.getint(state_level);         } else {             // initialize members default values new instance         }         ...     }     //you can retrieve saved values here      public void onrestoreinstancestate(bundle savedinstancestate) {         // call superclass can restore view hierarchy         super.onrestoreinstancestate(savedinstancestate);          // restore state members saved instance         mcurrentscore = savedinstancestate.getint(state_score);         mcurrentlevel = savedinstancestate.getint(state_level);     } 

click here find more this


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -