'I am getting transactionlargeexception error when sharing a photo with intent in android

This is my share code. I can share with StartActivity but the app crashes in the background. The error is here and my app crashes. Thank in advence.

val bitmapUri = Uri.parse(bitmapPath)
                val sendIntent = Intent(Intent.ACTION_SEND)
                sendIntent.setType("image/*")
                sendIntent.putExtra(Intent.EXTRA_STREAM, bitmapUri)
                startActivity(Intent.createChooser(sendIntent, "share"))
 

java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 2706652 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:7861)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
     Caused by: android.os.TransactionTooLargeException: data parcel size 2706652 bytes
        at android.os.BinderProxy.transactNative(Native Method)
        at android.os.BinderProxy.transact(BinderProxy.java:540)
        at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4627)
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)


Solution 1:[1]

I found the problem. Actually, the error was not from the code above. The problem was that I was sending a large data with bundle. Remember, the reason for this error is that if you are using bundle, you have loaded big data on it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ERTUGRUL KOC