Hello, sorry to bother you but I have ran into another small problem that I can't figure out. I've watched tutorials, browsed stackoverflow and googled it and still can't get it working.

I'm making a really simple app where the user can change the application's background color by using a spinner in the actionbar.

The background color is saved as least temporary but as soon as I close the app, the chosen background color vanishes.

String Color_Value;
int mycolor;
int change=0;
View root;
View someView;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (savedInstanceState != null){
    savedInstanceState.getInt(Color_Value, mycolor);
    someView = findViewById(R.id.layout);

    someView.setBackgroundColor(mycolor);

}
public void ChangeBackgroundtoOrange(){

  mycolor = android.R.color.holo_orange_light;
  someView = findViewById(R.id.layout);
  root = someView.getRootView();
  root.setBackgroundColor(getResources().getColor(android.R.color.holo_orange_light));
  Toast.makeText(getBaseContext(), "Color Changed", Toast.LENGTH_SHORT).show(); 

}
public void onSaveInstanceState(Bundle outState){
outState.putInt(Color_Value, mycolor);
super.onSaveInstanceState(outState);
}
public void onRestoreInstanceState(Bundle savedInstanceState){
savedInstanceState.getInt(Color_Value);
super.onRestoreInstanceState(savedInstanceState);

}

For simplicities sake, I've taken out most of the code but if the user were to select orange, how can I make it so the app will defaut to the orange background the next time I open the app? Thank you for your time.

SharedPreferences is the simplest way to persist your app changes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.