title: CursorWindowAllocationException from MediaStore.Images.Thumbnails.getThumbnail
body: <p>I am getting an occasional (quite rare) exception from MediaStore.Images.Thumbnails.getThumbnail (see below). Similar questions were advised to always close the cursor, but I am not performing an explicit query. </p>
  
  <p>I call it like this:</p>
  
  <p>a private function reading the thumbnails.. (</p>
  
  <pre><code>      private Bitmap getThumbnail(long imageId) { return MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), imageId,
        MediaStore.Images.Thumbnails.MINI_KIND, null); }
  </code></pre>
  
  <p>It is called from here:</p>
  
  <pre><code>Cursor cursor = null;
  int numProcessed = 0, numFaceDetected = 0;
  try {
    dirtyFile.createNewFile();
  
    String[] projection = {
        MediaStore.Images.Media._ID,
        MediaStore.Images.Media.DATA,
        MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
        MediaStore.Images.Media.ORIENTATION
    };
  
    cursor = getContentResolver().query(
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
        projection,
        null,
        null,
        MediaStore.Images.Media.DATE_ADDED + " desc");
  
    if (cursor == null) {
      return;
    }
  
    cursor.moveToFirst();
    final int columnIndexId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    final int columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    final int columnIndexOrientation = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION);
    final int columnIndexBucketName = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
  
    while (!cursor.isAfterLast()) {
      final long imageId = cursor.getLong(columnIndexId);
      final String imagePath = cursor.getString(columnIndexData);
      final int imageOrientation = cursor.getInt(columnIndexOrientation);
  
      Bitmap bitmap = getThumbnail(imageId);
      faceDetect(bitmap); 
  
      cursor.moveToNext();
      numProcessed++;
  
    }
  </code></pre>
  
  <p>Here is the exception:</p>
  
  <pre><code>android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
         at android.database.CursorWindow.(CursorWindow.java:137)
         at android.database.CursorWindow.(CursorWindow.java:42)
         at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
         at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
         at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
         at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
         at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:30)
         at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
         at android.content.ContentResolver.query(ContentResolver.java:478)
         at android.content.ContentResolver.query(ContentResolver.java:422)
         at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:680)
         at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:1060)
  </code></pre>