title: Android - sharedPreference are not working as it should?
body: <p>I have an ArrayList of string in my activity and  i want to store it as onPause in SharedPreference and retrieve it in my onCreate() but i am unable to do that.</p>
  
  <p>here is my code -:</p>
  
  <pre><code>public static ArrayList&lt;String&gt; ignoredTasks;
  public static final String PREF_FILE_NAME = "savedPreferences";
  
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
      ignoredTasks =  loadBackStates();
  }
  @Override
  public void onPause()
  {
      super.onPause();
      Log.e(TAG, "I am pause");
      saveState();
  }
  @Override
  public void onStop()
  {
      super.onStop();
      Log.e(TAG, "I am stop");
      saveState();
  }
  @Override
  public void onDestroy()
  {
      super.onDestroy();
      Log.e(TAG, "i am destroy");
      saveState();
  }
  
  public void saveState()
  {
      SharedPreferences spr = getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = spr.edit();
      int size = ignoredTasks.size();
      editor.putInt("size", size);
      for(int k = 0; k &lt; size-1; k++)
      {
          editor.putString(k+"4", ignoredTasks.get(k));
          editor.commit();
      }
  
      //editor.commit();
  }
  public ArrayList&lt;String&gt; loadBackStates()
  {
       ArrayList&lt;String&gt; ignoredTask = new ArrayList&lt;String&gt;();
      SharedPreferences sp = getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
      int size = sp.getInt("size", 0);
      for(int k = 0; k &lt; size-1; k++)
      {
          ignoredTask.add(k, sp.getString(k + "4", " "));
      }
      return ignoredTask;
  
  }
  
  
  public void createMenuDialog(final int i, Drawable icon, final String taskName, final String pkgName)
  {
      final AlertDialog.Builder menuDialog = new AlertDialog.Builder(this);
      menuDialog.setIcon(icon);
       menuDialog.setTitle(taskName);
  menuDialog.setItems(menuItems, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
  
                      /* User clicked so do some stuff */
                      String[] items = menuItems;
  
                      if(items[which].equals("Ignore"))
                      {
                          HashMap&lt;String,String&gt; newItem = new HashMap&lt;String,String&gt;();
                          newItem.put("Process", pkgName);
                          newItem.put("Name", taskName);
                          ignored.add(newItem);
                          ignoredTasks.add(pkgName);
                      }                                               
                  }
              });
       menuDialog.show();
  }
  </code></pre>
  
  <p>The problem is when i exit my app using back key and then if i restart it again, i could see the sharedpreference but when i force close my app then its gone. what's the issue?</p>
  
  <p>Please Help!!</p>
  
  <p>Thanks</p>