0

I am developing an android application which have seven sliders in one page. ie, seven questions are there and one slider corresponding to each questions. Users can answer the question by sliding the pointer in each slider. In S3 this page is crashing. We are using high resolution images for this section.

Is this due to less heap size in S3? Can we resolve this issue? Is there any method to over come this issue? For this frame, do we need to use images with less-quality(It's not desirable)?

Venu V
  • 73
  • 5

3 Answers3

0

Are you loading Bitmaps Efficiently?

If yes then you can try to increase the heap size by using

android:largeHeap="true"

in your <application> tag in the AndroidManifest file.

Warning:

  • Larger heap size means longer GC(Garbage Collection) time.
  • If you make your app heap size bigger, it will significantly slow down other apps and users will soon know your app is the problem.
  • Don't use this option just because you get memory error.
Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • http://www.youtube.com/watch?v=_CruQY55HOk. More the heap memory, more frequent garbage collection. The guy in the video gives a big warning about using large heap. – Raghunandan Apr 01 '13 at 10:29
  • Thank you for your fast response. The first thing i need to know is, Is this possible to resolve this issue in S3 with higher resolution images? – Venu V Apr 01 '13 at 10:30
  • @Raghunandan I know but you can use it if you need your app damn to be executed with no more options available. – Lalit Poptani Apr 01 '13 at 10:30
  • @ Venu V consider the warning before using large heap. – Raghunandan Apr 01 '13 at 10:35
0

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html.

Load bitmaps efficiently. See the link under the topic Load a Scaled Down Version into Memory.

Recycle bitmaps when not in use.

http://www.youtube.com/watch?v=_CruQY55HOk. The talk is about Memory management. If run it memory leaks , you can use MAT Analyzer to find and fix the issue. The video also talks about heap and use of MAT Analyzer.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

Use the below method to set the Image in ImageView got from this link worked for me

  public Bitmap ShrinkBitmap(String file, int width, int height){

             BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
                bmpFactoryOptions.inJustDecodeBounds = true;
                Bitmap bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);

                int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height);
                int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width);

                if (heightRatio > 1 || widthRatio > 1)
                {
                 if (heightRatio > widthRatio)
                 {
                  bmpFactoryOptions.inSampleSize = heightRatio;
                 } else {
                  bmpFactoryOptions.inSampleSize = widthRatio;
                 }
                }

                bmpFactoryOptions.inJustDecodeBounds = false;
                bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
             return bitmap;
            }
Community
  • 1
  • 1
Auto-Droid ツ
  • 1,583
  • 1
  • 17
  • 31
  • http://www.youtube.com/watch?v=_CruQY55HOk. The guy in the video gives a warning about using System.gc();. – Raghunandan Apr 01 '13 at 10:34
  • sorry my video streaming is slow so I am not able to watch the video but I have used system.gc() and it has not cause any trouble for me – Auto-Droid ツ Apr 01 '13 at 11:09
  • @ Auto-Droid check the link http://stackoverflow.com/questions/2414105/why-is-it-a-bad-practice-to-call-system-gc. – Raghunandan Apr 01 '13 at 11:11