2016年1月10日 星期日

onSaveInstanteState and onRestoreInstanceState

onSaveInstanteState and onRestoreInstanceState

when will they be call

Whatever the app has been close or destroy or not by the system,when the use go back, the app, the app should be the same before exit, this two method use on this way.



example:
if we save simething in a arraylist,after,rotate,the arraylist will be come empty,if we want to restore it:

step1 
 @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelableArrayList(MOVIE_KEY,movieArrayList);
    }


step2

inonCreate or onRestoreInstanceState


getBack


movieArrayList= (ArrayList<Movie>) savedInstanceState.get(MOVIE_KEY);