views:

47

answers:

1

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

+1  A: 

I'm sure you thought of it, but nevertheless: Have you included

<uses-permission android:name="android.permission.SET_WALLPAPER" />

in your manifest-file?

You're sure there is no exception thrown? It could possibly be a problem with showing the Toast.

walla
Yes I have and it works on my phone and various other phones that I have tried it on. In order to replicate the error what I did was make the image larger and It is infact a problem with attempting to allocate too much memory for the bitmap. I'll change the question to reflect this.
Kman