I'm having memory problems and think it might have to do with creating large bitmaps.
The task at hand is to get a fairly small tile image and create a larger tiled image and set this as the phone wallpaper. The way I'm doing this is:
1) Create a view that is 2 * screen width, 1 * screen height
2) Set the view background to a BitmapDrawable with the tile mode set to repeat
3) Create a bitmap with the views dimensions
4) draw the view to the bitmap by: view.draw(new Canvas(bitmap))
5) set wallpper: getApplicationContext().setWallpaper(bitmap)
This works fine on my phone (HTC Magic) and other phones that I have tried. But I am getting bug reports relating to this issue. I tried to recreate the problem by doubling the required dimensions and the problem seems to be happening in the 4th step when the view is being drawn to the bitmap:
ERROR/dalvikvm-heap(124): Heap Massage needed (7372800-byte external allocation too big)
I'm not sure how to go about solving this. Please help! Thanks
Unfortunately, I don't think you can do much... We are on a mobile phone here ; Android limis the process memory to 16MB.
Here are a couple of tips and tricks I can give you (because I have the sames issues in my application)
Are you sure you need 32 bits pixels? that's three 8bit color channels plus a 8bit alpha channel. You can use RGB_565 for a visually acceptable result.
Recycle the image that you don't need when you create your bitmap (and that you won't need to draw your bitmap)
null
any other object that you don't needRun
System.gc()
to force a garbage collection just before you create theBitmap
Hope this helps!
Actually you could refactor your code. You'll have better performance and probably use less memory if you don't use a
View
Bitmap
of the desired sizebitmap = Bitmap.createBitmap(width,height,Bitamp.Config.RGV_565)
(orARGB_8888
, that might work too)canvas = new Canvas(bitmap)
src
simplified Code:
Keep the end set wallpaper
getApplicationContext().setWallpaper(bitmap)
Not exactly sure if this is your solution, but have you looked at ? BitmapFactory.Options.inTempStorage
The way you use it is:
I'm sure you thought of it, but nevertheless: Have you included
in your manifest-file?
You're sure there is no exception thrown? It could possibly be a problem with showing the Toast.