Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListFragment doesn't save the bundle in onSaveInstanceState()/doesn't retrieve bundle in onActivityCreated()
    primarykey
    data
    text
    <p>I'm new to android and I'm facing the following problem. I'm developing for both, Android 2 and 3, and this is why I use fragments. However to make the app working on Android 2 devices I import android.support.v4.app.ListFragment. I need to maintain selection within my ListFragment when orientation of the screen changes. I'm overriding <code>onSaveInstanceState()</code> method and put an int into the bundle. When the screen is rotated, this method is called and the int is added to the bundle. However when <code>onActivityCreated()</code> is called, its bundle is null. I am following the example provided on Android website: <a href="http://developer.android.com/reference/android/app/Fragment.html" rel="noreferrer">http://developer.android.com/reference/android/app/Fragment.html</a>, but as mentioned above - after <code>onSaveInstanceState()</code> is called, the bundle in <code>onActivityCreated()</code> is still null.</p> <p>Here's the code:</p> <pre><code>import android.support.v4.app.ListFragment; public class VisitsHomeFragment extends ListFragment { private int selectedPosition = -1; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState != null) { if (savedInstanceState.containsKey("SELECTED_POSITION")) { selectedPosition = savedInstanceState.getInt("SELECTED_POSITION"); } } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("SELECTED_POSITION", selectedPosition); } } </code></pre> <p>I would appreciate any help with this problem.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload