0

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.

2
Contributors
1
Reply
3
Views
3 Years
Discussion Span
Last Post by peter_budo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.