I am implementing SensorEventListner
in my activities.
I am having three activities where SensorEventListner
is implementing to detect shake motion. In all three activities differently, I am registering the sensorListner onCreate
and unregistering the listner onPause
. On call of every activity it registers again and then `unregisters onPause.
My app having allocated heap size as 3.6MB while heap size of device is 16MB still getting Force close with the error in LogCat as:
" OutOfMemoryException: bitmap size exceeds VM budget" EDIT: Logcat error
06-13 15:47:35.056: ERROR/AndroidRuntime(10377): Uncaught handler: thread main exiting due to uncaught exception
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.content.res.Resources.loadDrawable(Resources.java:1705)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.content.res.Resources.getDrawable(Resources.java:580)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.widget.ImageView.resolveUri(ImageView.java:548)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.widget.ImageView.setImageResource(ImageView.java:270)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at com.nga.flashcards.activities.GardenActivity.display(GardenActivity.java:1024)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at com.nga.flashcards.activities.GardenActivity.onSensorChanged(GardenActivity.java:1352)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:435)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.os.Handler.dispatchMessage(Handler.java:99)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.os.Looper.loop(Looper.java:123)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at android.app.ActivityThread.main(ActivityThread.java:4595)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at java.lang.reflect.Method.invoke(Method.java:521)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-13 15:47:35.196: ERROR/AndroidRuntime(10377): at dalvik.system.NativeStart.main(Native Method)
I am also having large amount images and changing images in imageview through setImageResource(). Getting error on using SensorEventListner. If sensor event is not used in app then working fine.
My questions are :
Wheather there are any issues related to memory while registering and unregistering listener again and again in the app?
Are there any memory leaks, if yes then how to detect and what can be the solution to the problem?