简体   繁体   中英

Can a handler with big msg.obj throw TransactionTooLargeException?

I noticed that there are a lot of exceptions reported in Google Console:

java.lang.RuntimeException: 
  at android.app.servertransaction.PendingTransactionActions$StopInfo.run (PendingTransactionActions.java:160)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:201)
  at android.app.ActivityThread.main (ActivityThread.java:6815)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)
Caused by: android.os.TransactionTooLargeException: 
  at android.os.BinderProxy.transactNative (BinderProxy.java)
  at android.os.BinderProxy.transact (BinderProxy.java:1131)
  at android.app.IActivityManager$Stub$Proxy.activityStopped (IActivityManager.java:3973)
  at android.app.servertransaction.PendingTransactionActions$StopInfo.run (PendingTransactionActions.java:144)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:201)
  at android.app.ActivityThread.main (ActivityThread.java:6815)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)

I'm trying to figure out what is throwing that exception, but I can't. The only suspicious thing I have in my source coude is a part in which I'm loading a very big json file (7MB), parsing it to a model ( data object) with GSON, and passing it throught a handler to my activity:

Message msg = new Message();
msg.what = Util.THREAD_DATA_GENERATED;
msg.obj = data;
handler.sendMessage(msg);

. . .

notifyHandler = new Handler(new Handler.Callback() {
    @Override
    public boolean handleMessage(Message msg) {
        Data data = (Data) msg.obj;
        Manager.getInstance().setData(data);
        showSelectTeamDialog();
        return true;
    }
});

Can this handler throw that exception when passing a msg.obj parameter with a big size?

A handler wont. But sending that data via an Intent to an Activity can. The data is serialized for possible cross-process messaging, and there's a data size limit (at one time it was 2MB, unsure if that's changed). I would bet that showSelectTeamDialog is launching an Activity to show the dialog, and that's what's failing.

Look at the stack trace. It included:

at android.app.IActivityManager$Stub$Proxy.activityStopped (IActivityManager.java:3973)

So the activity was stopped for some reason. The only reason that would happen is if finish was called, or if another activity was launched. So we're definitely seeing too much data in an Intent here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM