All Products
Search
Document Center

Mobile Testing - Deprecated:android_os_TransactionTooLargeException

Last Updated:Feb 21, 2023

Problem description

The data transmitted by Binder is added to the Parcel class. If the request or response parameters of Binder are more than 1 MB in size and cannot be stored in the transaction buffer, the invocation fails and the TransactionTooLargeException occurs.

android.os.TransactionTooLargeException
    at android.os.BinderProxy.transact(Native Method)
    at com.android.internal.view.IInputMethodManager$Stub$Proxy.startInput(IInputMethodManager.java:604)
    at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1173)
    at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1282)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3201)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)

Solution

If the request or response parameters of Binder are excessive in size, the invocation fails and the TransactionTooLargeException occurs. We recommend that you do not transfer large arrays, strings, or bitmaps to Binder.

Sample code

public class MainActivity extends Activity {
    private IDictionaryManager mDictionaryManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent = new Intent();
        intent.setAction("android.intent.action.DictionaryManagerService");
        intent.setPackage("com.wanginbeijing.dictionaryserver");
        bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
        // Add a word.
        findViewById(R.id.btn_add).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    mDictionaryManager.add("Morning", "Hello");
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
        // View the word.
        findViewById(R.id.btn_query).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    String english = mDictionaryManager.query("Morning");
                    Toast.makeText(MainActivity.this,english, Toast.LENGTH_SHORT).show();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    private ServiceConnection mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            IDictionaryManager dictionaryManager = IDictionaryManager.Stub.asInterface(iBinder);
            try {
                mDictionaryManager = dictionaryManager;
                Toast.makeText(MainActivity.this, "connect success", Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                Toast.makeText(MainActivity.this, "connect failed", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
        @Override
        public void onServiceDisconnected(ComponentName name) {
        }
    };
}

References