title: Restore Android GridView after screen orientation change (without reloading it)
body: <p>I'm new to Android (this is my first application) and I made a <code>GridView</code> in an <code>Activity</code> which I'd like it to be responsive according to screen position (portrait / landscape). Of course I made some custom layout values of <code>GridView</code> rows width for portrait as well as for landscape, and it works perfectly.</p>
  <p>Except that, on every screen orientation change, the <code>GridView</code> is reloading again. And that's not good for user experience. I only like the <code>GridView</code> (and definitely its rows) to adjust to new screen width without doing all the <code>onCreate()</code> instructions (retrieving <code>GridView</code>'s data from internet, assigning retrieved data in a <code>HashMap</code> object, setting the <code>GridView</code>'s <code>Adapter</code>, then display the <code>GridView</code>'s rows).</p>
  <p>I went through many forum threads and some Google documentation that talk about restoring simple values, but never found an answer for restoring a <code>GridView</code> without having it to reload again.</p>
  <p>I read about <code>onSaveInstanceState()</code> and <code>onRestoreInstanceState()</code>, but I didn't know how to use them in my case (<code>GridView</code> case).</p>
  <p>Could any one provide a simple code sample for this? Or at least some headlines to follow?</p>
  <p>Here's some of what I tried in my code, in the <code>Activity</code> class :</p>
  <pre><code>    private Parcelable mListInstanceState;
      private Parcelable mAdapterInstanceState;
  
      private GridView gridView = null;
      private MyAdapter myAdapter = null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
  
         gridView = (GridView) findViewById(R.id.gridview);
  
         // Check whether we're recreating a previously destroyed instance
         if(savedInstanceState != null) {
              // Restore value of members from saved state
              mListInstanceState = savedInstanceState.getParcelable(&quot;gridview&quot;);
              mAdapterInstanceState = savedInstanceState.getParcelable(&quot;adapter&quot;);
         }
         else {
              // Retrieve data from internet, fill HashMap object, 
              // set Adapter and display GridView only for the first time the activity is created
              attemptToDisplayGirdViewItems();
         }
      }
  
      @Override
      protected void onSaveInstanceState(Bundle state) {
          // Save activity state
  
          super.onSaveInstanceState(state);
  
          state.putParcelable(&quot;gridview&quot;, gridView.onSaveInstanceState());
          // state.putParcelable(&quot;adapter&quot;, myAdapter);               
      }
  
      @Override
      protected void onRestoreInstanceState(Bundle savedInstanceState) {
          // Retrieve and restore activity state
  
          // Restore state members from saved instance
          mListInstanceState = savedInstanceState.getParcelable(&quot;gridview&quot;);
          mAdapterInstanceState = savedInstanceState.getParcelable(&quot;adapter&quot;);
  
          super.onRestoreInstanceState(savedInstanceState);
      }
  </code></pre>