By pressing the button, it is necessary that it retains its state, and after restarting the activity was in an inactive state.
Write somewhere the state of the button, and the next time you start it count. How can this be achieved?

  • one
    Write somewhere the state of the button. Next time you start reading. - lampa pm
  • What to do when someone answered your question - pavlofff

2 answers 2

Can be saved to SharedPreferences

  final static String BUTTON_PRESSED = "button_pressed"; 

Save at the touch of a button

  SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); sharedPref.edit() .putBoolean(BUTTON_PRESSED, true) .apply(); 

Get, for example, in onCreate()

  SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); boolean isButtonPressed = sharedPref.getBoolean(BUTTON_PRESSED, false); 

more

    Most likely, you used to switch activities Intent. Take the putextra () function and put Boolean in it, depending on the value of which the activity will take one or another form.