title: Saving the ListView state in android
body: <p>I have a ListView in my main page(<strong>MainActivity.java</strong>) and I want to keep the ListView's position(if it was scrolled up I want to show the exact ListView position) when user comes back to main page.</p>
  
  <p>Since the MainActivity goes to onPause() -> onStop() method when the user clicked a list item,
  I am saving the state of ListView inside onPause(). For get the return <strong>Parcelable</strong> value I use a global variable called <strong>state</strong>.</p>
  
  <pre><code>state = list.onSaveInstanceState(); //line 1
  </code></pre>
  
  <p>When the user comes back to the MainActivity() it goes through the onStart(), so I get the saved states inside onStart().</p>
  
  <pre><code>if (state != null) {
          //set adapter to listview
          list.setAdapter(myAdapter);
          //Restore previous state
          list.onRestoreInstanceState(state);
  }
  </code></pre>
  
  <p>The problem is <strong>line 1</strong> doesn't return any state.(It gives a null value).
  How to fix this?</p>
  
  <p>Thanks.</p>