I understand that this question is asked several times. None of them are clear from the solution. Let me explain the problem.
- I have an Activity that uploads 4 images at a time.
- I upload images to the onResume () method.
- When loading Activity gives an error of the raster image.
Notes.
- I set the image using the setImageResource (R.drawable.xxxx) method, not bitmap / drawables.
- Images are scaled correctly.
- The WORKS FINE activity in all emulators is up to 2.3 and is the WORKING PART in a real device (Samsung Galaxy 5).
- The error appears during the first initialization, and the orientation change event does not start. Images
- They have a size of 800 x 600 and average values โโof 15kb (each).
Let me know any solutions. Also let me know if you have similar problems with Android 2.3.3 emulator.
[update] -snippets
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... img_topLeft = (ImageView) findViewById(R.id.Img_Alph_Q_TopLeft); img_topRight = (ImageView) findViewById(R.id.Img_Alph_Q_TopRight); img_bottomLeft = (ImageView) findViewById(R.id.Img_Alph_Q_BottomLeft); img_bottomRight = (ImageView) findViewById(R.id.Img_Alph_Q_BottomRight); ... } protected void onResume() { super.onResume(); img_topLeft.setImageResource(R.drawable.xxx); img_topRight.setImageResource(R.drawable.xxx); img_bottomLeft.setImageResource(R.drawable.xxx); img_bottomRight.setImageResource(R.drawable.xxx); ... }
03-21 08: 59: 17.362: ERROR / dalvikvm-heap (5883): external allocation of 4320000 bytes is too large for this process. 03-21 08: 59: 17.412: ERROR / GraphicsJNI (5883): VM will not allow us to allocate 4320000 bytes 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): FATAL EXCEPTION: main 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): java.lang.OutOfMemoryError: the size of the bitmap exceeds the budget VM 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.graphics.Bitmap.nativeCreate (native method) 03 -21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.graphics.Bitmap.createBitmap (Bitmap.java:477) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.graphics .Bitmap.createBitmap (Bitmap.java:444) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.graphics.Bitmap.createScaledBitmap (Bitmap.javahaps49) 03-21 08: 59: 17.432 : ERROR / AndroidRuntime (5883): at android.graphics.BitmapFactory.finishDecode (BitmapFactory.java:498) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883 ): at android.graphics.BitmapFactory.decodeStream (BitmapFactory.javarige73) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.graphics.BitmapFactory.decodeResourceStream (BitmapFactory.javahaps36) 03- 21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.graphics.drawable.Drawable.createFromResourceStream (Drawable.java:697) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android. content.res.Resources.loadDrawable (Resources.java:1709) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.content.res.Resources.getDrawable (Resources.javacla81) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): on android.widget.ImageView.resolveUri (ImageView.javaโบ01) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): on android.widget.ImageView .setImageResource (ImageView.java:280) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at Quiz.java:124) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): Quiz. onResume (Quiz.java:92) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1150) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.Activity.performResume (Activity.java: 3832) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.ActivityThread.performResumeActivity (ActivityThread.java:2110) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:2135) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:1668) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.ActivityThread.access $ 1500 (ActivityThread.java:117) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:931) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.os.Handler.dispatchMessage (Handler.java:99) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (58 83): at android.os.Looper.loop (Looper.java:123) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at android.app.ActivityThread.main (ActivityThread.javahaps683) 03 -21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at java.lang.reflect.Method.invokeNative (native method) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at java.lang. reflect.Method.invoke (Method.java:507) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:839) 03 -21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at com.android.internal.os.ZygoteInit.main (ZygoteInit.javaโ97) 03-21 08: 59: 17.432: ERROR / AndroidRuntime (5883): at dalvik.system.NativeStart.main (native method)
Thanks. I managed to solve the problem. Code sharing for others A custom class that resolved this issue. based on @ Janardhanan.S.
public class BitmapResizer { public static Bitmap decodeImage(Resources res, int id ,int requiredSize){ try { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, id, o);
GSree
source share