My application has this piece of code
mView.setDrawingCacheEnabled(true); mBitmap = Bitmap.createBitmap(mView.getDrawingCache());
Where mView is an instance of a custom subclass of FrameLayout. The app has been working well for 6 months with thousands of users. Recently, I got several reports (possibly from the same user, but I canβt confirm) about the empty pointer passed to createBitmap (). I do not know which hardware or version of Android you are using.
What can cause getDrawingCache () to return null even if I include the cache directly in front of it? Is this related to hardware acceleration in new phones? Is it due to insufficient ram for the bitmap? Anything else? Can this be prevented?
Edit: I found this solution here http://tinyurl.com/7yranvj . Is this a smart decision?
mBitmap = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(mBitMap); mView.draw(canvas);
source share