title: Remove item from SharedPreference when removed from Listview
body: <p>In my code, with the help of context menu I'm able to delete a particular item from Listview but as I'm using sharedpreferences to save arraylist called "places" then it restores the sharedpreference when the app is launched back again. Now how should I implement my sharedpreferences such that when a particular item is deleted from listview, the same item also gets deleted from arraylist "places" of shared preferences.</p>
  
  <p>Below is my code snippet</p>
  
  <pre><code>static ArrayList&lt;String&gt; places = new ArrayList&lt;String&gt;();
      static ArrayList&lt;LatLng&gt; locations = new ArrayList&lt;&gt;();   //to save lat and long
      static ArrayAdapter arrayAdapter;
      public ListView listView;
      SharedPreferences sharedPreferences;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          listView = (ListView) findViewById(R.id.listView);
  
          sharedPreferences = this.getSharedPreferences("com.starprojects.memorableplaces", Context.MODE_PRIVATE);
          registerForContextMenu(listView);
  
          //tricker locations
          ArrayList&lt;String&gt; latitudes = new ArrayList&lt;&gt;();
          ArrayList&lt;String&gt; longitudes = new ArrayList&lt;&gt;();
  
          //initially set
          places.clear();
          latitudes.clear();
          longitudes.clear();
          locations.clear();
  
  
          //to restore
          try {
  
              places = (ArrayList&lt;String&gt;) ObjectSerializer.deserialize(sharedPreferences.getString("places", ObjectSerializer.serialize(new ArrayList&lt;&gt;())));
  
              latitudes = (ArrayList&lt;String&gt;) ObjectSerializer.deserialize(sharedPreferences.getString("latitudes", ObjectSerializer.serialize(new ArrayList&lt;&gt;())));
  
              longitudes = (ArrayList&lt;String&gt;) ObjectSerializer.deserialize(sharedPreferences.getString("longitudes", ObjectSerializer.serialize(new ArrayList&lt;&gt;())));
  
              Log.i("palces",places.toString());
  
          } catch (IOException e) {
  
              e.printStackTrace();
  
          }
  
  @Override
      public boolean onContextItemSelected(MenuItem item) {
  
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
           // sharedPreferences = getSharedPreferences("places",0);
            SharedPreferences.Editor editor = sharedPreferences.edit();
  
              if((item.getTitle()).equals("Delete"))
              {
                  places.remove(info.position);
  
                  editor.remove("places");   //problem is here, how to get particular index to be removed from arraylist places and save it.
                  editor.commit();
  
                  arrayAdapter.notifyDataSetChanged();
  
                  return true;
              }
            return super.onContextItemSelected(item);
  
  
         }
  }
  </code></pre>