Need to utilise the camera in my app for work, I see that things have changed in API >= 28 compared to how I used to do it where I could use startActivityForResult.
However I am facing a problem where I launch the camera app, and immediately get the 'TransactionTooLargeException' error message in the debug/run console.
For calling up the camera, I am doing
mGetContent = registerForActivityResult(
new ActivityResultContracts.TakePicture(),
result -> {
if (result) {
}
}
);
Where mGetContent is defined in the class as
private ActivityResultLauncher<Uri> mGetContent;
In my AndroidManifest.xml file I have the following
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
In my file_paths file I have
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="files"
path="."/>
<files-path
name="app_images"
path="./files/"/>
</paths>
I have a button set up in my activity where I launch the camera using
findViewById(R.id.button)).setOnClickListener(v -> {
File directory = new File(context.getFilesDir(), "app_images");
if (!directory.exists()) directory.mkdir();
File file = new File(directory, "image.jpg");
Uri uri = getUriForFile(this, "com.test.fileprovider", file);
mGetContent.launch(uri);
};
As soon as I tap on the button, and the camera app opens up, I get what I can only assume is an overly general error message.
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 1284092)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test, PID: 14296
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1284092 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:161)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: android.os.TransactionTooLargeException: data parcel size 1284092 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:511)
at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4524)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)
Been trying to Google search to find things, but having trouble nailing down what the actual issue is.
Some suggestions pointed me towards the onSaveInstanceState, so I override that and set a breakpoint on it to see what was happening, but it made it through without any issues (from what I could tell).
Kind of at a loss with this one.
Wowsers as to what makes up the bundle in the onSaveInstanceState.
I have some imageviews, imagebuttons, and just general buttons in my app to make things easier for our staff.
I went through and changed the 'saveState' of all the ImageViews and ImageButtons from the default of true to false, since I don't care what state they were in, they are just visual guides.
Took the android:viewHierarchyState from 1.2MB down to 1.6KB, my Parcel size is now 3.3KB and it no longer crashes when suspending the app to bring up the camera app.
TooLargeTool was useful, but I couldn't make it work the way the Github page says, I told it to 'startLogging', and in my activity where the crash was happening, I set a breakpoint and checked if it was logging using 'isLogging' and it came back 'true'.
In the end I just had it log the output of TooLargeTool.bundleBreakdown(outState)
in the onSaveInstanceState.
Thanks to Gabe Sechan and ianhanniballake for pointing me towards what it might be, there's not much out there on for this particular exception, I mean, there is, but it appears that it is different for everyone.
Really wish Google would print out a better set of error messages for it to make it easier to work out which activity was the problem (or in my case, all 3 activities combined).