How to resolve the java.lang.RuntimeException error: android.os.TransactionTooLargeException

0

I'm having this error when I try to share a bitmap via try in Android 7.0, I already researched a lot and could not solve it, so I saw Google itself has the recommendation to avoid the error link but I could not understand the proposed solution or find another alternative.

This is the Google sample code, I did not understand the DataFragment class what it is.

public class MyActivity extends Activity {

    private RetainedFragment dataFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // find the retained fragment on activity restarts
        FragmentManager fm = getFragmentManager();
        dataFragment = (DataFragment) fm.findFragmentByTag(“data”);

        // create the fragment and data the first time
        if (dataFragment == null) {
            // add the fragment
            dataFragment = new DataFragment();
            fm.beginTransaction().add(dataFragment, “data”).commit();
            // load the data from the web
            dataFragment.setData(loadMyData());
        }

        // the data is available in dataFragment.getData()
        ...
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        // store the data in the fragment
        dataFragment.setData(collectMyLoadedData());
    }
}
    
asked by anonymous 22.03.2017 / 19:40

1 answer

3

ERROR

This can occur when you pass large amounts of data through parameters of a Intent !

When you receive this exception in your application, see if you are swapping too much data between your services!

Using Intent to share huge data, (for example, the user selects a huge number of gallery sharing files, the URIs of the selected files will be transferred using Intents ).

In your case, try to pass the image ( Bitmap ) to Intent save it to somewhere (some system folder) and only share URI .

Without your code, it's hard to help!

CODE

The code you added above is a solution that instead of setting the parameters via Bundle

EXAMPLE:

    FragmentManager dataFragment = new FragmentManager();
    Bundle bundle = new Bundle();
    bundle.putSerializable("dataObject", loadMyData());   //parameters are (key, value).
    dataFragment.setArguments(bundle);
    fm.beginTransaction().add(dataFragment, “data”).commit();

You can add directly to via Set:

  // load the data from the web
   dataFragment.setData(loadMyData());

Source1

Source2

    
23.03.2017 / 21:54