The reason, why the state is reseted is that your activity is completely destroyed and then restored again due to Android architecture. To store state of your button you should rather save it state into the Bundle in onSaveInstaceState() and restore in onRestoreInstanceState() - these methods are designed specifically for this kind of tasks.
So the answer is you should implement saving/restoring button state in two methods:
@Override
protected void onSaveInstanceState (Bundle outState) {
// Your code here
}
@Override
protected void onRestoreInstanceState (Bundle savedInstanceState) {
// Your code here
}
Details see in docs:
Note the "Killable" column in the above table -- for those methods that are marked as being killable, after that method returns the process hosting the activity may killed by the system at any time without another line of its code being executed. Because of this, you should use the onPause() method to write any persistent data (such as user edits) to storage. In addition, the method onSaveInstanceState(Bundle) is called before placing the activity in such a background state, allowing you to save away any dynamic instance state in your activity into the given Bundle, to be later received in onCreate(Bundle) if the activity needs to be re-created. See the Process Lifecycle section for more information on how the lifecycle of a process is tied to the activities it is hosting. Note that it is important to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not part of the lifecycle callbacks, so will not be called in every situation as described in its documentation.