Answer the question
In order to leave comments, you need to log in
How to keep changed Int variable when reopening Activity?
The scenario is as follows: through Activity #1 I go ( startActivityForResult
) to Activity #2, where the player turns on, in Activity #2 I press the turn button, the value turn_ok = 2 is assigned there, then returns ( setResult(RESULT_OK, intent);
) Activity #1, the next time Activity #2 is opened, check for turn_ok value, if turn_ok = 2, then stop player playback.
In Activity #2, a variable is declared before onCreate:
In Activity #2, when creating, a check is made in onCreate:private int turn_ok;
if(turn_ok == 2){
playlistManager.invokeStop();
turn_ok = 1;
}
public void onClick_turn (View v){
turn_ok = 2;
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
startActivityForResult
. Answer the question
In order to leave comments, you need to log in
To save the state of the activity or any values use SaveInstanceState or SharedPreference
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question