title: How to Save multiple images to ImageView using Shared Preferences
body: <p>I have a activity with a couple of ImageViews. The user can LongPress an ImageView and they have the option of getting any image from the camera gallery. I am trying to save the imagepath of those images so that when the user closes and opens the app again the image will still be in the imageView. I dont understand why this isn't working.</p>
  
  <p>Here is my Activity A where the imageView is</p>
  
  <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
      if (requestCode == SELECT_PICTURE) {
      Uri selectedImageUri = data.getData();
      selectedImagePath = getPath(selectedImageUri);
      System.out.println("Image Path : " + selectedImagePath);
      im1.setImageURI(selectedImageUri);}}}
  
  public String getPath(Uri uri) {
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = managedQuery(uri, projection, null, null, null);
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      return cursor.getString(column_index);};
  
      @Override
  protected void onPause() {
      SharedPreferences sp = getSharedPreferences("AppSharedPref", 1); // Open SharedPreferences with name AppSharedPref
      Editor editor = sp.edit();
      editor.putString("ImagePath", selectedImagePath); // Store selectedImagePath with key "ImagePath". This key will be then used to retrieve data.         
      editor.commit();
      super.onPause();
      }   
  
  protected void onResume1() {
      SharedPreferences sp = getSharedPreferences("AppSharedPref", 1);
      selectedImagePath = sp.getString("ImagePath", "");
      super.onResume();
      }
  </code></pre>
  
  <p>And Activity B gets the cam gallery pic and sends back to Activity A</p>
  
  <pre><code> Button send = (Button) findViewById(R.id.send);
      send.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
              Intent intent=new Intent();
              setResult(RESULT_OK, intent);
              Bundle bundle=new Bundle();
              bundle.putInt("image",R.id.showImg);
              intent.putExtras(bundle);
              finish();  }
              });
   public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
          if (requestCode == SELECT_PICTURE) {
              Uri selectedImageUri = data.getData();
              selectedImagePath = getPath(selectedImageUri);
              System.out.println("Image Path : " + selectedImagePath);
              img.setImageURI(selectedImageUri);
          }}}
   public String getPath(Uri uri) {
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = managedQuery(uri, projection, null, null, null);
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      return cursor.getString(column_index);
      }
  </code></pre>