0

I have android app which works fine on my tablet, but it crashes when you load an activity on my phone.

The thing that seems odd to me is the main title page loads without problems when you launch the app, however when I load either the game activity or just the instructions page activity the app will crash.

The title page consists of a background image, and 3 image buttons while the instructions page consists of a background image of the same resolution and 2 out of the 3 same buttons from the title page activity. So it effectively loads less images is what I am getting at, yet it crashes when attempting to load that activity.

Here is the stack trace:

07-25 12:51:14.841  16090-16090/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bitrump.fishygame, PID: 16090
java.lang.OutOfMemoryError: Failed to allocate a 132710412 byte allocation with 16777120 free bytes and 72MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:816)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:637)
        at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:665)
        at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:695)
        at bitrump.fishygame.gameGraphics.onCreate(gameGraphics.java:41)
        at android.app.Activity.performCreate(Activity.java:6374)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
        at android.app.ActivityThread.access$900(ActivityThread.java:182)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:6141)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Does anyone have any information on how to make the app more efficient? It is crashing on one of the newest phones out there, a galaxy s6. The tablet which it works on by the way is an nvidia shield tablet.

krump
  • 3
  • 2
  • What is the size of bitmap you are creating? From message it looks like around 126 MB? Is that correct? – Wand Maker Jul 25 '15 at 18:21
  • The largest one would be my background image at 252kb. – krump Jul 25 '15 at 18:27
  • Perhaps this may help http://stackoverflow.com/questions/29861929/java-lang-outofmemoryerror-android – Wand Maker Jul 25 '15 at 18:29
  • Thanks, it appears to be due to my background images. Whenever I took the background images out of both activities completely they work. I'll need to look into a better way to have the background images I want. – krump Jul 25 '15 at 18:34

2 Answers2

0

This is due to your background image, what you need to do is simply get an image which is less size and more pixel quality which is done by designer(do ur self).

Search stackoverflow same qustion so many times all ready asked:

xxxhdpi: 1280x1920 px
xxhdpi: 960x1600 px
xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px

Please Go With Developer Docs

Community
  • 1
  • 1
Guruprasad
  • 931
  • 11
  • 16
0

Several things of note:

If this is a static banner image, you should just be using the "size" buckets provided by Android by default and let an Android ImageView take care of properly scaling, loading, and unloading.

http://developer.android.com/guide/practices/screens_support.html

If you need this image to "hang around" remember big images take up a lot of memory. Downsampling is your friend. You can do so while loading the image into memory if you want with the inSampleSize, but the granularity is not so great. It works on powers of two. I.E. you can decrease the image size by half each time. This usually isn't an option for most applications as you lose too much image quality.

http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize

Follow these guidelines if you MUST scale it, personally I would avoid that.

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

Now this isn't a "solution" per-say, but if your app is hungry, adding a large heap flag might help somewhat. For QA and development leave this out. If you're depending on it you're probably doing it wrong.

http://developer.android.com/reference/android/R.styleable.html#AndroidManifestApplication_largeHeap

I would have to see more code to give a better answer.

accordionfolder
  • 573
  • 4
  • 17