title: Can't save Arraylist state on fragment
body: <p>sorry for bringing another question. </p>
  
  <p>I've tried to solve by my own, but I can't. </p>
  
  <p>I want to save the state from a Arraylist from a fragment inside an Activity. Basically, it's a JSON that populates by PHP script a List in a ListFragment. Then, the item clicked sends the Name and Details from the clicked item. </p>
  
  <p>Finally, when the user hits the button "Add to cart", those data goes to a Arraylist in the third fragment at the same Activity.</p>
  
  <p>The code:</p>
  
  <p><strong>PedidosFragment.java</strong></p>
  
  <pre><code>package com.example.waitersoriginal;
  
  *some imports*
  
  public class PedidosFragment extends ListFragment{
  
      public ArrayList&lt;HashMap&lt;String, String&gt;&gt; listaPedidos;
  
      private static final String TAG_NM = "NOME";
      private static final String TAG_DS = "DESCR";
  
      ListAdapter adapter2;
  
      public PedidosFragment(){}
  
      @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) 
      { 
          //abc = savedInstanceState;
  
          super.onCreate(savedInstanceState);
          restore(savedInstanceState);
  
          listaPedidos = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          adapter2 = new SimpleAdapter(getActivity(), listaPedidos,
                  R.layout.list_item, 
                  new String[] { TAG_NM, TAG_DS}, 
                  new int[] { R.id.name, R.id.pid});
  
          setListAdapter(adapter2);
  
        return inflater.inflate(R.layout.pedidos_fragment, container, false); 
      }
  
      void criaArray(String nomeProd, String descrProd) {
  
  
          HashMap&lt;String, String&gt; map3 = new HashMap&lt;String, String&gt;();           
          map3.put(TAG_NM, nomeProd);
          map3.put(TAG_DS, descrProd);
  
          listaPedidos.add(map3);    
  
              //getListView();
              ((BaseAdapter) adapter2).notifyDataSetChanged();
      }   
  
      @Override
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putSerializable("listaPedidos", listaPedidos);
      }
  
      private void restore(Bundle savedInstanceState) {
          if (savedInstanceState != null) {
              listaPedidos = (ArrayList&lt;HashMap&lt;String,String&gt;&gt;) savedInstanceState.getSerializable("listaPedidos"); 
          }
      }
  
  }
  </code></pre>
  
  <p>When I leave the actual activity and enter again, the Arraylist has gone. What am I doing wrong ? </p>
  
  <p>EDIT:</p>
  
  <p>Changing onCreateView with the suggestion given:</p>
  
  <pre><code>public PedidosFragment(){}
  
      @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) 
      { 
          //abc = savedInstanceState;
  
          super.onCreate(savedInstanceState);     
  
          listaPedidos = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          restore(savedInstanceState);
  
          adapter2 = new SimpleAdapter(getActivity(), listaPedidos,
                  R.layout.list_item, 
                  new String[] { TAG_NM, TAG_DS}, 
                  new int[] { R.id.name, R.id.pid});
  
          setListAdapter(adapter2);
  
        return inflater.inflate(R.layout.pedidos_fragment, container, false); 
      }
  </code></pre>