What you need to do, instead of using KeyCode Back, you will override the method below in your activity
@Override public void onBackPressed() { super.onBackPressed(); }
And save the state of your button using SharedPrefrence , and the next time you enter your Activity, get the value from Sharedpreference and set the enabled state of your button accordingly.
Example,
private void SavePreferences(){ SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("state", button.isEnabled()); editor.commit();
Andro selva
source share