I am having a TransactionTooLargeException when I close/minimize my app. I am assuming it is due to my Bundle being too large (3 JSONArrays as strings), but it would be great if someone can diagnose more information from my error trace.
Here it is:
05-28 17:17:25.994 9518-9518/com.adamtrudeauarcaro.godbuilder E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 551100)
05-28 17:17:25.996 9518-9518/com.adamtrudeauarcaro.godbuilder D/AndroidRuntime: Shutting down VM
05-28 17:17:25.998 9518-9518/com.adamtrudeauarcaro.godbuilder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.godbuilder, PID: 9518
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 551100 bytes
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4211)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: android.os.TransactionTooLargeException: data parcel size 551100 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:628)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:4132)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4203)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
From your error trace it doesn't say, but I can tell you from experience certainly that this happens when your bundle is too large to store it as a saved instance state. Which means that when you minimize the app, it tries to call onSaveInstanceState and your bundle is storing more data than the supported by the system.
I encountered this exception before too. The scenario is we pass paths of all pictures or videos in album through Bundle to preview fragment, usually it is OK, but it becomes a problem when there are thousands of files in user's device. The exception will be thrown when activity stops and application is reclaimed by system, during which the argument data are passed to system through binder for restore later. Here is the exception trace:
Thread Name: 'main'
Back traces starts.
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 2352912 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:161)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:263)
at android.app.ActivityThread.main(ActivityThread.java:8246)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
Caused by: android.os.TransactionTooLargeException: data parcel size 2352912 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:568)
at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4429)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)
... 7 more
Back traces ends.
To fix it, we restraint only one hundred paths around the current clicked picture or video. Here are the codes.
val selections = ArrayList<Selection>()
// The number of pictures in user device can be more than 1000.
// Restrict the list size to fix TransactionTooLargeException: data parcel size too large.
val interval = 100
val start: Int = max(0, position - interval / 2)
val end: Int = min(materials.size - 1, start + interval)
for (i in start..end) {
val albumItem: IAlbumItem = materials[i]
val selection = Selection(Triple("null", i, -1), Pair(-1, -1), albumItem)
selection.what = what
selections.add(selection)
}
val bundle = Bundle()
// The collection has changed, the position should offset the same too.
bundle.putLong("limitVideoDuration", limitVideoDuration)
bundle.putInt("position", position - start)
bundle.putSerializable("selections", selections)
Related
I am using lottie compose with ViewPager.
val composition by rememberLottieComposition(LottieCompositionSpec.Asset(tutorial.lottieSrc))
val progress by animateLottieCompositionAsState(composition)
val lottieAnimatable = rememberLottieAnimatable()
LaunchedEffect(Unit) {
lottieAnimatable.animate(
composition,
iteration = LottieConstants.IterateForever
)
}
LottieAnimation(
composition = composition,
progress = { progress },
modifier = Modifier
.size(220.dp)
)
This causes OutOfMemory.
Each page uses lottie and the average size is around 4MB.
I think it's not that big size. But my guess is, since it's viewpager, it loads duplicate lottile on the memory.
I get this error:
Clamp target GC heap from 51MB to 48MB
And then when the app crashes.
java.lang.OutOfMemoryError: Failed to allocate a 12 byte allocation with 0 free bytes and -16B until OOM
at androidx.compose.runtime.CompositionImpl.addPendingInvalidationsLocked(Composition.kt:674)
at androidx.compose.runtime.CompositionImpl.drainPendingModificationsLocked(Composition.kt:566)
at androidx.compose.runtime.CompositionImpl.recordModificationsOf(Composition.kt:656)
at androidx.compose.runtime.Recomposer.recordComposerModificationsLocked(Recomposer.kt:417)
at androidx.compose.runtime.Recomposer.access$recordComposerModificationsLocked(Recomposer.kt:125)
at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2.invokeSuspend(Recomposer.kt:499)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock#b1d76ac, androidx.compose.ui.platform.MotionDurationScaleImpl#abc1f75, StandaloneCoroutine{Cancelling}#d2d3b0a, AndroidUiDispatcher#7fb5f7b]
Is there any solution for this?
Referes:
https://google.github.io/accompanist/pager/
https://github.com/airbnb/lottie/blob/master/android-compose.md
2022-02-01 12:01:30.862 16616-16616/? E/ActivityThread: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ChooserActivity$1#efec398 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ChooserActivity$1#efec398 that was originally registered here. Are you missing a call to unregisterReceiver()?
at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1607)
at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1378)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1624)
at android.app.ContextImpl.registerReceiverAsUser(ContextImpl.java:1611)
at android.content.ContextWrapper.registerReceiverAsUser(ContextWrapper.java:720)
at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:98)
at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:86)
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:523)
at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:828)
at android.app.Activity.performCreate(Activity.java:8127)
at android.app.Activity.performCreate(Activity.java:8098)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3513)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3700)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8061)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
2022-02-01 12:01:30.871 714-721/? E/statsd: Predicate 5980654721335871649 dropping data for dimension key (10)0x2010101->10036[I] (10)0x30000->launch[S]
2022-02-01 12:01:30.897 18012-18012/com.athermobileapp E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 1250432)
2022-02-01 12:01:30.923 18012-18012/com.athermobileapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.athermobileapp, PID: 18012
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1250432 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:161)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8061)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: android.os.TransactionTooLargeException: data parcel size 1250432 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:593)
at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4647)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8061)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
You aren't running out of memory, so calling gc won't help (its also not reliable, and not necessary as Java will run gc if it needs to). Your problem is you're sending an intent that is too big. See the part of the crash that says android.os.TransactionTooLargeException: data parcel size 1250432 bytes? An intent's data can be a maximum of 1 MB. You're at about 1.2 MB. You need to decrease the amount of data in your intent.
In my app I start a foreground service and create a notification for it:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
...
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.icon));
...
This throws an exception on one of my users devices like below (a java.lang.RuntimeException: Could not copy bitmap to parcel blob. exception).
My icons do have default dimensions and small sizes, don't know why they make problems on one device.
Does anyone know what the real issue could be? And how I could avoid this issue or gracefully handle this case? Seems to be a memory issue.
Mipmap icon
I have included following icons:
mdpi (48x48, 3,51kB)
hdpi (72x72, 6,65kB)
xhdpi (96x96, 9,08kB)
xxhdpi (144x144, 17,2kB)
xxxhdpi (192x192, 22,0kB)
Exception
java.lang.RuntimeException: Unable to start service com.my.app.services.OverlayService#ea0edcc with Intent { act=RESUME cmp=com.my.app/.services.OverlayService }: java.lang.RuntimeException: Could not copy bitmap to parcel blob.
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3079)
at android.app.ActivityThread.access$2200(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5585)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.RuntimeException: Could not copy bitmap to parcel blob.
at android.graphics.Bitmap.nativeWriteToParcel(Native Method)
at android.graphics.Bitmap.writeToParcel(Bitmap.java:1541)
at android.graphics.drawable.Icon.writeToParcel(Icon.java:705)
at android.os.Parcel.writeParcelable(Parcel.java:1437)
at android.os.Parcel.writeValue(Parcel.java:1343)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:711)
at android.app.Notification.writeToParcel(Notification.java:1731)
at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:701)
at android.app.NotificationManager.notify(NotificationManager.java:230)
at android.app.NotificationManager.notify(NotificationManager.java:194)
at com.my.app.services.BaseOverlayService.a(SourceFile:39)
at com.my.app.services.BaseOverlayService.a(SourceFile:23)
at com.my.app.services.OverlayService.onStartCommand(SourceFile:136)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3062)
I have got a strange memory leak on samsung devices. If I do a lot of navigations then it produces an OutOfMemoryException with this StackTrace:
Exception: Failed to allocate a 276060 byte allocation with 184864 free bytes and 180KB until OOM
StackTrace:
--- End of managed Java.Lang.OutOfMemoryError stack trace ---
java.lang.OutOfMemoryError: Failed to allocate a 276060 byte allocation with 184864 free bytes and 180KB until OOM
**at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
at android.graphics.Bitmap.createBitmap(Bitmap.java:948)
at android.graphics.Bitmap.createBitmap(Bitmap.java:915)
at android.widget.TextView$MagnifierView.getContentsBitmap(TextView.java:14862)
at android.widget.TextView$MagnifierView.<init>(TextView.java:14806)
at android.widget.TextView.getMagnifierView(TextView.java:14707)**
at android.widget.Editor.onDetachedFromWindow(Editor.java:469)
at android.widget.TextView.onDetachedFromWindowInternal(TextView.java:6224)
at android.view.View.dispatchDetachedFromWindow(View.java:16766)
at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:5154)
at md58b29b5ebe7ec5add1ba4eaa7f6c6bb96.EventDetailsView_1.n_onDestroy(Native Method)
at md58b29b5ebe7ec5add1ba4eaa7f6c6bb96.EventDetailsView_1.onDestroy(EventDetailsView_1.java:47)
at android.app.Activity.performDestroy(Activity.java:7210)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1161)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4621)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4661)
at android.app.ActivityThread.-wrap7(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1703)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Does anybody have an idea what these lines (See below) do and why the hell it allocates memory (Bitmap) when it is being destroyed?
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
at android.graphics.Bitmap.createBitmap(Bitmap.java:948)
at android.graphics.Bitmap.createBitmap(Bitmap.java:915)
at android.widget.TextView$MagnifierView.getContentsBitmap(TextView.java:14862)
at android.widget.TextView$MagnifierView.<init>(TextView.java:14806)
at android.widget.TextView.getMagnifierView(TextView.java:14707)**
As far I understand from my testing, the activities are kept in memory even after OnDestroyed or Finish are called. If I navigate back and wait a minute I see the free memory is climbing again. Otherwise, the allocated memory get's bigger and at some point there is not enough space to do another navigation so the system tries to free memory by destroying an old activity. But this activity is allocating memory (MagnifierView) which isn't free during the Destroy-Process.
When I do the same on a Xperia Z5, the memory is freed right after a back navigation.
I want to change the background image of my Activity's layout every time I launch that activity. For that reason, inside onResume(), I am randomly setting the background image of layout like this:
#Override
public void onResume(){
super.onResume();
Random r = new Random();
int randNumber = r.nextInt(homeBackgroundImage.length);
mBackgroundLayout.setBackground(ResourcesCompat.getDrawable(getResources(), homeBackgroundImage[randNumber], null));
}
But, I am getting exception in the following line:
mBackgroundLayout.setBackground(ResourcesCompat.getDrawable(getResources(), homeBackgroundImage[randNumber], null));
This is the logcat output:
java.lang.OutOfMemoryError: Failed to allocate a 756946956 byte allocation with 16777216 free bytes and 433MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.Resources.getDrawable(Resources.java:806)
at android.support.v4.content.res.ResourcesCompatApi21.getDrawable(ResourcesCompatApi21.java:27)
at android.support.v4.content.res.ResourcesCompat.getDrawable(ResourcesCompat.java:60)
at in.avara.app.avaravrplayer.Activity.MainActivity.onResume(MainActivity.java:167)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
at android.app.Activity.performResume(Activity.java:6327)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Someone, please suggest me What is the optimized and best way to change background image of a layout randomly on every launch.
NOTE: I have already tried adding android:hardwareAccelerated="false" , android:largeHeap="true". But, it didn't work in my case.
Thanks in advance!
You are attempting to allocate 756946956 bytes ~= 721MB. This is much too large.
Moreover, 756946956 bytes represents the equivalent of a 13756 x 13756 pixel image. This is far larger than any Android screen.
You need to identify the image that is failing and reduce its resolution significantly.
If you put this image in res/drawable/, bear in mind that res/drawable/ is a synonym of res/drawable-mdpi/. Your image will be upsampled when you use that drawable on higher screen densities (e.g., xhdpi). You probably should move that drawable out of res/drawable/ and into either a density-specific directory for the desired density (e.g., res/drawable-xhdpi/), or into res/drawable-nodpi/ to disable this density-based resampling.
Try to put move your images from res/drawable/ to res/drawable/drawable-nodpi. If problem is still here, in your manifest under application put android:largeHeap="true".