OutOfMemoryError captureSharedElementState androidL - android

I've been experimenting Shared elements transitions with Android-L preview (Nexus 7), and faced OutOfMemoryError exceptions when used with a ViewPager. But I also tried on Romain's google-io-2014 demo, and got the same problem after clicking on a picture then hitting back, a couple of times (between 10 to 15). Is it a bug in the SDK, and there's something that should be done on the application side (recycle())?
java.lang.OutOfMemoryError: Failed to allocate a 1817612 byte allocation with 772936 free bytes
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:810)
at android.graphics.Bitmap.createBitmap(Bitmap.java:787)
at android.graphics.Bitmap.createBitmap(Bitmap.java:754)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:543)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:511)
at android.app.EnterTransitionCoordinator.sendSharedElementDestination(EnterTransitionCoordinator.java:109)
at android.app.EnterTransitionCoordinator.onReceiveResult(EnterTransitionCoordinator.java:151)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:738)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
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:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
I/am_crash( 612): [17912,0,com.example.android.io2014,8961606,java.lang.OutOfMemoryError,Failed to allocate a 1817612 byte allocation with 772936 free bytes,VMRuntime.java,-2]
Update (10/17/2014): all fixed with SDK 21. Can't close the question.

Apparently this has been fixed in API 21 (according to the OP).
Note also that Romain Guy's sample project is just an example... he didn't bother writing code that properly scales down the images he uses (which is what you would normally do in a production application). If you are running the sample on a low-end device, it's possible that you might get out of memory errors. To avoid this, I recommend resizing and scaling down the drawable PNGs included in the project.

Related

Android Studio Out Of Memory Error when i run app

When i run my application on a physical device
Every time the application crashes. The LogCat displays "Out of memory and Failed to allocate a 74649612 byte allocation with 16768392 free bytes and 49MB until OOM "
The device I am using is Xiaomi RedMi note 4
3GB RAM
Android version 7.0
Processor Qualcomm Snapdragon 625
Here is the LogCat message
java.lang.OutOfMemoryError: Failed to allocate a 74649612 byte allocation with 16768392 free bytes and 49MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1272)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:308)
at android.content.res.Resources.getDrawable(Resources.java:785)
at android.content.res.Resources.getDrawable(Resources.java:756)
at com.suman.udit.su.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6852)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2700)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6365)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
Looks like the Drawable (picture, perhaps?) you are trying to load at MainActivity.java:52 is too big. You also might try putting it in the drawable-nodpi folder, so that the system doesn't try to re-scale it upon load.
OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.
As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
you should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently
Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.
Here some of possible answers for these type of errors in SOF
Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap
How to solve java.lang.OutOfMemoryError trouble in Android
Android : java.lang.OutOfMemoryError
java.lang.OutOfMemoryError
Solution for OutOfMemoryError: bitmap size exceeds VM budget

Crosswalk Crash: java.lang.RuntimeException: org.xwalk.core.XWalkView.onTouchEvent

Of course understanding that Crosswalk is no longer being updated, I have encountered a pretty notable issue that I don't really know what to do with. Ever since I updated my Android apps' Crosswalk from 14 to 23, I've been seeing an alarmingly large volume of Google Play crash reports related to org.xwalk.core.XWalkView.onTouchEvent on a broad array of Android versions and devices. I've looked around Google/StackOverflow with no success, and to be honest don't even know where to start in diagnosing the issue since I haven't been able to replicate it myself. A sample stack trace is below.
Any recommendations? Even tips on paths to move forward to figuring out what is going on would be great. I would rather not strip Crosswalk from my app since I do have a non-insignificant number of Android <5.0 users.
Thanks!
java.lang.RuntimeException: at
org.xwalk.core.XWalkView.onTouchEvent(XWalkView.java:1689) at
android.view.View.dispatchTouchEvent(View.java:10011) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2344) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2675)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2301) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2675)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2301) at
android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2675)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2301) at
com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:437)
at
com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1814)
at android.app.Activity.dispatchTouchEvent(Activity.java:3070) at
com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:386)
at android.view.View.dispatchPointerEvent(View.java:10251) at
android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4659)
at
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4517)
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4028)
at
android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4087)
at
android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4053)
at
android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4061)
at
android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4259)
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4033)
at
android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4087)
at
android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4053)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4061)
at
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4033)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6459)
at
android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6427)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6381)
at
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6562)
at
android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:216)
at android.os.MessageQueue.nativePollOnce(Native Method:0) at
android.os.MessageQueue.next(MessageQueue.java:323) at
android.os.Looper.loop(Looper.java:145) at
android.app.ActivityThread.main(ActivityThread.java:6459) at
java.lang.reflect.Method.invoke(Native Method:0) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:938)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)

Android Studio not installing particular application in particular device

Okay i have this strange situation... I have a project in android studio that was working fine till last night but when i uninstalled the application and made clean and rerun attempt to install the app it takes forever to install the app
Now the situation is i have other projects in android studio which i tried to run in the same device and they are installing fine. So i think the device is good.
I tried to run the same project on other device and it worked completely fine so i think the android studio as well as my code is fine.
i thought the uninstalling was the issue so i cleared cached data of device and it dint work. So anyone having idea how to resolve this issue?
I have tried everything like clean and rerun, invalidate cache and restart etc so suggest something else. Tell me if you want something from the code.
Edit :
Now I changed the package name of the project so that if the previous app gave some problem during uninstalling then it should treat this app as new application because i changed the package name but still it isn't working.
Try to remove it from other users as well if any exists in your device.
I found the solution. Actually i found the error due to which the android studio was taking forever to install the apk... it was not able to allocate memory during run time. This was the error i was getting.
java.lang.OutOfMemoryError: Failed to allocate a 191692812 byte allocation with 12539072 free bytes and 110MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:613)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:446)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:973)
at android.content.res.Resources.createFromResourceStream(Resources.java:2771)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2472)
at android.content.res.Resources.loadDrawable(Resources.java:2370)
at com.miui.internal.variable.v21.Android_Content_Res_Resources_class.handleLoadDrawable(SourceFile:40)
at android.content.res.MiuiResources.loadDrawable(MiuiResources.java:393)
at android.content.res.Resources.getDrawable(Resources.java:776)
at android.content.res.Resources.getDrawable(Resources.java:742)
at android.app.ApplicationPackageManager.getDrawable(ApplicationPackageManager.java:743)
at android.app.MiuiThemeHelper.getDrawable(MiuiThemeHelper.java:103)
at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:157)
at android.app.ApplicationPackageManager.getApplicationIcon(ApplicationPackageManager.java:800)
at com.miui.permcenter.install.AdbInstallActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5982)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5237)
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:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)

Out memory error

Hi i have been doing a project from school and when i ran my application i have the stack trace error shown below.
03-06 14:58:02.520 11265-11265/com.example.ray.cdmsv2 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
at android.content.res.Resources.loadDrawable(Resources.java:2970)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.TintManager.getDrawable(TintManager.java:147)
at android.support.design.widget.TabLayout$Tab.setIcon(TabLayout.java:1080)
at com.example.ray.cdmsv2.Activities.CreateTaskActivity.onCreate(CreateTaskActivity.java:102)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
I have looked around for solution but i still cannot resolve the issue. My application is able to run smoothly on Samsung Galaxy A3. However when i tried to run my application on a S4 and Note 4 i receive the out of memory error. I have realized that when i implement some selector in my drawable which i call in my XML files, it will cause the error, however when i remove it the error does not occur anymore. Is there any explanation for this issue? Thank you very much for helping me out
Delete the drawable and import it again using ImageAsset option.
The error is your image is too heavy for loading it into memory. Or better compress the image before copying it into the Drawable folder.
I would start by learning some best practices for memory usage by google at the dev docs #
http://developer.android.com/training/displaying-bitmaps/index.html
If you're loading large bitmaps, its quite possible the available heap memory is not enough for your bitmaps.
Your app is being choked by Android because it is using more memory than assigned, primarily due to a large image file being used as a drawable.
If it is an icon, use Android Studio's built in Image Asset generator to generate appropriate image sizes for each display type (mdpi,hdpi,xhdpi,xxhdpi and so on). If it is an image being loaded on an ImageView, you may try using the Picasso library which will handle bitmap memory on its own.

Is there a workaround for using espresso with Lollipop (Android 21)?

Attempting to run a test with UI-related code using espresso (i.e. GoogleInstrumentationTestRunner) on a Nexus 7 with Lollipop gives the following error:
java.lang.IllegalStateException: This message cannot be recycled because it is still in use.
at android.os.Message.recycle(Message.java:279)
at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:468)
at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl.loopMainThreadUntilIdle(UiControllerImpl.java:337)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run(ViewInteraction.java:94)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
This has apparently been a known issue for several months but since there have been no commits since January 8, it is unknown whether there will be an official fix.
There is a comment in the discussion thread that states
Just removing message.recycle(); seems to fix it...
Is this a valid workaround? If not, what would the correct fix be?
UPDATE: Use Espresso 2.0 for Lollipop support
https://code.google.com/p/android-test-kit/wiki/EspressoSetupInstructions
Yes, if you remove "message.recycle(); " and rebuild it will solve that problem.
The Espresso team announced at GTAC that the next release of Espresso will be in AOSP before too long. See video here: https://www.youtube.com/watch?v=aHcmsK9jfGU
( I was the original poster of that issue you referenced )
UPDATE:
// you will want to keep it for older API versions
if ( SDK_INT < 21 ){
message.recycle();
}

Categories

Resources