Android 位图循环();显示错误,不显示图像

Android 位图循环();显示错误,不显示图像,android,Android,我在我的代码中尝试了回收方法,但它似乎无法正常工作。我在应用程序的开头有一个viewpager,其中有大约5个图像,我使用位图回收来回收它 Bitmap tempImage = ImageSampleManager.decodeSampledBitmapFromResource(getResources(),tutorial_images[position], 240, 240); view.setImageBitmap(tempImage); (

我在我的代码中尝试了回收方法,但它似乎无法正常工作。我在应用程序的开头有一个viewpager,其中有大约5个图像,我使用位图回收来回收它

        Bitmap tempImage = ImageSampleManager.decodeSampledBitmapFromResource(getResources(),tutorial_images[position], 240, 240);
        view.setImageBitmap(tempImage);
        ((ViewPager) collection).addView(view, 0);
        tempImage.recycle();
        return view;
    }  

通过阅读文档,可以避免创建stackoverflow主题并等待答案。 Bitmap.recycle用于通知系统您不再使用此位图,并且可以将其从内存中释放。 因此,如果先回收,当然不能显示它

您必须检查:

   Bitmap tempImage;
   if (tempImage != null && !tempImage .isRecycled()) {
                tempImage = null;
   }
    tempImage = ImageSampleManager.decodeSampledBitmapFromResource(getResources(),tutorial_images[position], 240, 240);
    view.setImageBitmap(tempImage);
    ((ViewPager) collection).addView(view, 0);
   // tempImage.recycle();
    return view; 

它不能正常工作-可能是编程中最无用的语句。你到底得到了什么错误,什么时候得到的,请从logcat发布堆栈跟踪。使用位图时,不能回收位图。“回收”会从内存中释放位图,可能是因为您调用了tempImage。过早回收:视图仍在使用该图像,因此尝试回收将失败。如果可能的话,试着在onDestroy中调用它。还有,能给我们看一些日志也很好。那么我到底应该做什么呢