W
W
Who_Is_Who2018-09-17 15:13:37
Java
Who_Is_Who, 2018-09-17 15:13:37

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;
        }

When you click on the turn button in Activity #2, the following happens:
public void onClick_turn (View v){
        turn_ok = 2;
        Intent intent = new Intent();
        setResult(RESULT_OK, intent);
        finish();
    }

You need to save the changed variable (turn_ok = 2) the next time you open Activity #2 via startActivityForResult.
It turns out you need to somehow overwrite the variable.
I tried through putExtra, but the result is zero, since it is not yet known how to bring it to one variable.
How to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Kovalev, 2018-09-17
@Who_Is_Who

To save the state of the activity or any values ​​use SaveInstanceState or SharedPreference

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question