Q:

Screen orientation landscape change activity

I'm making an app that change the colors depending of the color you select this change the background, but when I make the screen orientation to landscape this automatically change the color to the predefined and if I'm not wrong this happen because it's being destroy after I change the orientation... so I would like to know where and how I can solve that problem.

A:

Android gives you a chance to save state before changing the layout
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   if (savedInstanceState != null) {
      mColor = savedInstanceState.getString(COLOR_VALUE);
   }

@Override //this method is called before android trashes and recreates your activity
protected void onSaveInstanceState (Bundle outState) {
    super.onSaveInstanceState(outState);
   outState.putString(COLOR_VALUE, mColor);
}

If your UI is expensive to recreate then look into retained fragments instead

