0

I am creating an application and in there I am sending very big data in Bundle from Service to the Activity. But I am not using Messenger for that. Instead, I am assigning data to a variable in singleton class and then I am retrieving data from that singleton class and assigning it to the activity.

In the Activity, I have a ViewPager in which two fragments are inflated. The Bundle is being sent to both of these Fragment classes.

Now, when the activity is paused, application is throwing following exception:

at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4209)
                                                                        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: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)
                                                                     Caused by: android.os.TransactionTooLargeException: data parcel size 4538408 bytes
                                                                        at android.os.BinderProxy.transactNative(Native Method)
                                                                        at android.os.BinderProxy.transact(Binder.java:628)
                                                                        at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:4183)
                                                                        at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4201)
                                                                        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: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) 

Please help.

Malwinder Singh
  • 6,644
  • 14
  • 65
  • 103

2 Answers2

1

The bundle is being sent to both of these fragment classes.

Do not put large things into the saved instance state Bundle. In the case of fragments, the "arguments" Bundle (setArguments()) becomes part of the saved instance state Bundle, and so do not put large things into the arguments Bundle. The saved instance state Bundle is for tiny bits of data: as little as possible, but enough for you to restore your UI state after your process is terminated.

Instead, do something else, such as:

  • Have the fragments call methods on the hosting activity to get this data, or
  • Use a ViewModel, so that this data is retained across configuration changes but is not part of the saved instance state Bundle
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
-2

From Android Developers - TransactionTooLargeException

The Binder transaction buffer has a limited fixed size, currently 1Mb

And from similar question: What to do on TransactionTooLargeException

Actually data size was around 500kb, and the IPC transaction buffer size is set to 1024KB.

So, data parcel size 4538408 bytes (4MB) is too large to send at once. Split it.

Toris
  • 2,348
  • 13
  • 16