0

I have created an Android application that contains 6 imageviews, and some texts.. the size of the APK file is about (2 Megabyte). When I run the application of a real Android Device (HTC One M8-eye) it takes about (66 MegaByte) RAM of the device (Allocated Memory).

I also used (leakcanary), and the result is (there is no leak) in this app.

Is it normal? is there any suggestions to reduce this size??

Any answer is appreciated.. Thanks

Kurdish Programmer
  • 403
  • 1
  • 4
  • 14
  • If you use high resolution images, that could be possible. – Daniel Zolnai Mar 18 '16 at 16:12
  • Yes it's normal. Depending on how you show your images and how big your images are, they may use 4 bytes per pixel so a 1mp image can take up to 4mb itself in memory. reducing it is possible by rescaling the image and changing the number of bytes used per image. A more detailed explanation here (based on an earlier answer I provided to another user): http://stackoverflow.com/questions/26926088/android-picasso-imageview-out-of-memory-exception-memoryleak/26926545#26926545 – kha Mar 18 '16 at 16:15
  • Thanks guys for the answer.. @DanielZolnai, this number 4 comes from **ARGB**, it is right? – Kurdish Programmer Mar 18 '16 at 17:42
  • It was not my comment, but yes, each pixel has 256 colors, which can be stored in 8 bits (2 to the power of 8), which is 1 byte. And the 3 color channels plus the alpha channel (ARGB) result in 4 * 1 byte. – Daniel Zolnai Mar 19 '16 at 10:01

1 Answers1

0

This problem can be solved by creating different drawable folders (LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI).

I also used the (android drawable importer plugin) to import photos and generate different sizes and put them to different drawable folders.


Following are some important information:

LDPI: Portrait: 200 X 320px. Landscape: 320 X 200px.
MDPI: Portrait: 320 X 480px. Landscape: 480 X 320px.
HDPI: Portrait: 480 X 800px. Landscape: 800 X 480px.
XHDPI: Portrait: 720 X 1280px. Landscape: 1280 X 720px.
XXHDPI: Portrait: 960 X 1600px. Landscape: 1600 X 960px.
XXXHDPI: Portrait: 1280 X 1920px. Landscape: 1920 X 1280px.

The Result:: Used ammount of RAM is reduced from 60 Mega to about 13 Mega.

Kurdish Programmer
  • 403
  • 1
  • 4
  • 14