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)