title: Handle screen rotation without losing data - Android
body: <p>I'm becoming crazy figuring out what is the best way to handle screen rotation. I read hundreds of questions/answers here but I'm really confused.</p>
  
  <p>How can I save myClass data before the activity is re-created so I can keep everything for redrawing activity without another useless initialization?</p>
  
  <p>Is there a cleaner and better way than parcelable?</p>
  
  <p>I need to handle rotation because I want to change layout in Landscape mode.</p>
  
  <pre><code>public class MtgoLifecounterActivity extends Activity {
  
      MyClass myClass;
  
      // Called when the activity is first created
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          If ( ?? first run...myClass == null ? ) {
              myClass = new MyClass();
          } else {
              // do other stuff but I need myClass istance with all values.
          }
          // I want that this is called only first time. 
          // then in case of rotation of screen, i want to restore the other instance of myClass which
          // is full of data.
      }
  </code></pre>