Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Save your Activity state

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 151
    Comment on it

    Android activity life cycle contains onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onDestroy() where we have another life cycle method that helps to save activity current state everytime.


    Basically Activity being destroy whenever user presses back button from the app but in some scenario when App get crash or killed because of low memory then activity recreates when user come back to activity. For this android provide onSaveInstanceState() method to save all user current state or values.


    Example to save activity current state -


    public void onRestoreInstanceState(Bundle savedInstanceState) {
    
    super.onRestoreInstanceState(savedInstanceState);
    
    mScore = savedInstanceState.getInt(SCORE);
    mLevel = savedInstanceState.getInt(LEVEL);}
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: