How do I avoid running out of memory for graphics for an Android app?

I am working on an Android application in Eclipse, and so far my program has not grown much due to the size of the dwarf. However, I already had a problem with the Out of Memory error. You see, I used graphics consisting exclusively of bitmap images and PNG in this program, and recently, when I tried to add a little more functionality to the program (mainly including several bitmap images and creating an additional sprite), it started to crash graphics constructor constructor β†’ sprite. When I tracked down the problem, it turned out to be an "Out of Memory" error, which was apparently caused by adding too many image files to the program and creating Drawables from them.

This will be a problem, since I really do not have a lot of graphic resources working in this program ... maybe around 20. I did not even start turning on the sound. These images are not so strange. My questions are as follows:

1) Are the programs for the Android phone really limited depending on how much memory they can use, or is it probably something other than images of resources 20-30 causing this error?

2) If the memory for Android applications is so terrible, it can’t even handle 20-30 image resources loaded into Drawables, which exist at the same time, whereas in the world you have to make decent graphics and sound for this thing?

Thank.

+3
source share
5

, , . Android 16 24 . . .

: x x (16 32 ).

:

  • . Android , , . .
  • ARGB_4444 (16 ), . .
  • , , gc.
  • , . , , ( , ).
+3

- 2

Android: hardwareAccelerated = "" android: largeHeap = "true"

, . .

+2

... Android ( ), :

  • ? SDK, ? , , , ( , , , - , ).

  • ? , , Drawable Drawable Rect ?

  • , ? . , 1-9 10-19 , ""?

  • ? ?

, ; , , . snafus , , new, , . , ( , ).

!

+1

. , (, 50x50), , , , . , . , 90 , 300x300 , .

, .

  • , .
  • , . , RGB 565, ARGB_4444 ARGB_8888, . BitmapFactory.Options .
  • , "" - , (, ), . , , , 2x.
  • Light Racer , , , , .
+1

Drawables - , , . , , . , , , , , Drawables , ; , , , , . , , , Drawables .

, , - , , , - , sprite, , .

16 , . , , - , . , .

0

Source: https://habr.com/ru/post/1744735/


All Articles