title: Attempted to access a cursor after it has been closed
body: <p>I'm using the following code to delete an image. It works the first time, but when I try to capture an image and delete it 
            I get a <code>StaleDataException</code>:</p>
  
  <pre><code>08-07 14:57:24.156: E/AndroidRuntime(789): java.lang.RuntimeException: Unable to               
         resume activity {com.example.cap_im/com.example.cap_im.MainActivity}:  
         android.database.StaleDataException: Attempted to access a cursor after it has been closed.
  </code></pre>
  
  <hr>
  
  <pre><code>public void deleteImageFromGallery(String captureimageid) {
      Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
  
      getContentResolver().delete(
              MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
              BaseColumns._ID + "=?", new String[] { captureimageid });
  
      String[] projection = { MediaStore.Images.ImageColumns.SIZE,
              MediaStore.Images.ImageColumns.DISPLAY_NAME,
              MediaStore.Images.ImageColumns.DATA, BaseColumns._ID, };
  
      Log.i("InfoLog", "on activityresult Uri u " + u.toString());
  
      try {
          if (u != null) {
              cursor = managedQuery(u, projection, null, null, null);
          }
          if ((cursor != null) &amp;&amp; (cursor.moveToLast())) {
  
              int i = getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                      BaseColumns._ID + "=" + cursor.getString(3),   null);
              Log.v(TAG, "Number of column deleted : " + i);
          }
      } finally {
          if (cursor != null) {
              cursor.close();
          }
      }
  }
  </code></pre>