Search code examples
androidandroid-memory

Android application killed because of many image


I develop android fragment with a GridList has many image items. When the start to this fragment, the pause screen and start slowly. Also, When start to this fragment multiple times(about 3 times), app was killed.

Code :

mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_tiro_com_arco), "Archery"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_ginastica_artistica), "Artistic Gymnastics"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_atletismo), "Athletics"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_badminton), "Badminton"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_basquetebol), "Basketball"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_volei_de_praia), "Beach Volleyball"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_ciclismo_bmx), "BMX Cycling"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_boxe), "Boxing"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_canoagem_slalom), "Canoe / Kayak Slalom"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_canoagem_velocidade), "Canoe / Kayak Sprint"));
mGridArray.add(new GridViewItem(getBitmap(R.drawable.rio2016_sports_pictogram_olympic_saltos_ornamentais), "Diving"));

(There are many lines in the same manner as above.)

Anyway, What can I try for this phenomenon? Have you a document or code for I refer?

I'm a beginner of Android. So my question may seem ridiculously easy. But if you give me the answer I really appreciate it. Thanks :)


Solution

  • Try reading Google's guides to 'Load Large Bitmaps Efficiently' and then to load bitmaps with AsyncTask, this should help you out. In fact, read all 5 topics in that guide. Scale the images and load only thumbnails in your GridView. :)