Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEi 123
6,924 PointsHow to fix SaveInstanceState?
Hello, I don't know where is my wrong, but I need a help..
I need to do SaveInstanceState to save the Background color of editText, but if I do rotation, the color is not save.. someone can please help me with that?
this is my code:
public class MainActivity extends AppCompatActivity { private static final String KEY_COLOR = "KEY_COLOR" ; private Button mButton; private EditText mEditText; private boolean mlsBlue;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_COLOR, mlsBlue);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton = (Button) findViewById(R.id.button);
mEditText = (EditText) findViewById(R.id.editText);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mEditText.setBackgroundResource(R.color.blue);
}
});
}
} Thanks a lot :)