When you close the app or Android requires more memory, onDestroy() is called and your app is removed from the memory.
- If you want to keep the color permanently, then set button's color in XML or during onCreate use findViewById to find the button and set it's color.
- If you want button color to be changed once on button click and then stay like that always, then you should save this information in SharedPreferences. Next time when you app is launched, check if SharedPreferences contains intended button color and if so, apply it.
SharedPreferences are used to store small amount of data in key-value pairs. They are saved in internal storage, so you will get the value even after phone reboots.
See examples for SharedPreferences below:
Saving Key-Value Sets
Android Shared preferences example