title: SkImageDecoder::Factory returned null while working with local resources
body: <p>I have a listview which is dynamically populated with items.
  Each item has image and text. I know this context is so repeating in others stackoverflow's questions. However I still can't find the solution.</p>
  
  <p>First I had only this call which successfully sets each image in the listview. </p>
  
  <pre><code>imageview.setImageResource(getResuID());
  </code></pre>
  
  <p>Nevertheless, I wanted to optimize this, following <a href="http://developer.android.com/training/displaying-bitmaps/load-bitmap.html" rel="nofollow noreferrer">google training guide</a>, due to slow scrolling and lag. </p>
  
  <p>Then I tried to use the code from training and the problem appeared. Now I get null all around from BitmapFactory.</p>
  
  <p>I <a href="https://stackoverflow.com/questions/18424864/listview-performance-is-slow">read</a> about async task and GC and I also tried to move the scaling to the <strong>AsyncTask</strong> which neither solved the issue. </p>
  
  <p>This is what I do:</p>
  
  <p>Calling the task from "getView" in my the listview adapter which extends from BaseAdapter:</p>
  
  <pre><code>int resID = getResID();
  AsyncImageSetter task = (AsyncImageSetter) new AsyncImageSetter(thumb_image,resID).execute();
  
  public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
          // Raw height and width of image
          final int height = options.outHeight;
          final int width = options.outWidth;
          int inSampleSize = 1;
  
          if (height &gt; reqHeight || width &gt; reqWidth) {
  
              final int halfHeight = height / 2;
              final int halfWidth = width / 2;
  
              // Calculate the largest inSampleSize value that is a power of 2 and keeps both
              // height and width larger than the requested height and width.
              while ((halfHeight / inSampleSize) &gt; reqHeight &amp;&amp; (halfWidth / inSampleSize) &gt; reqWidth) {
                  inSampleSize *= 2;
              }
          }
  
          return inSampleSize;
      }
  
      public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
  
          // First decode with inJustDecodeBounds=true to check dimensions
          final BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeResource(res, resId, options);
  
          // Calculate inSampleSize
          options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
  
          // Decode bitmap with inSampleSize set
          options.inJustDecodeBounds = false;
          return BitmapFactory.decodeResource(res, resId, options);
      }
  
      public class AsyncImageSetter extends AsyncTask&lt;Void, Void, Void&gt; {
  
          private ImageView img;
          private int image_resId;
          private Bitmap bmp; 
  
          public AsyncImageSetter(  ImageView img, int image_ResId ) {
  
              this.img = img;
              this.image_resId = image_ResId; 
  
          }
  
          @Override
          protected Void doInBackground(Void... params) {
               try {
                  Thread.sleep(100);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              bmp = (decodeSampledBitmapFromResource(activity.getResources(), image_resId, 100, 100)); 
  
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
  
              img.setImageBitmap(bmp);
              bmp = null;
  
              super.onPostExecute(result);
          }
  
      }
  </code></pre>
  
  <p>Receiving this log messages:</p>
  
  <pre><code>01-07 19:57:54.167: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.167: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.277: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.277: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.277: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.306: D/dalvikvm(2141): GC_CONCURRENT freed 1247K, 12% free 10097K/11463K, paused 5ms+6ms
  01-07 19:57:54.387: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.387: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.397: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.507: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.507: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.517: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.626: D/skia(2141): --- SkImageDecoder::Factory returned null
  01-07 19:57:54.626: D/skia(2141): --- SkImageDecoder::Factory returned null
  </code></pre>
  
  <p>Is that due to GC memory free?</p>
  
  <p>It's strange but if instead of          </p>
  
  <pre><code>bmp = (decodeSampledBitmapFromResource(activity.getResources(), resources.getResID(), 100, 100)); 
  </code></pre>
  
  <p>I use </p>
  
  <pre><code>bmp = (decodeSampledBitmapFromResource(activity.getResources(), R.drawable.image1, 100, 100)); 
  </code></pre>
  
  <p>It works "fine". I see all listview items with repeated image though. </p>
  
  <p>Also I tried to follow the BitmapFun sample to incorporate the caching, but it's really advanced sample. Maybe you could suggest me some easier way to do it without so many classes.</p>
  
  <p>Thanks</p>