To save any (small) parameters between application restarts, you can use the SharedPreferences class.
A simple example:
Add a field to the Activity class:
private SharedPreferences mSettings;
Next, in the onCreate() method, load and apply the saved color (if it was saved):
mSettings = getSharedPreferences("my_settings", Context.MODE_PRIVATE); if (mSettings.contains("my_background_color")) { int color = mSettings.getInt("my_background_color", 0); bglayout.setBackgroundColor(color); }
And in the onStop() method, save the color:
SharedPreferences.Editor editor = mSettings.edit(); Drawable background = bglayout.getBackground(); if (background instanceof ColorDrawable) editor.putInt("my_background_color", ((ColorDrawable) background).getColor()); editor.apply();