Reputation: 371
I am writing an application that renders a bunch of data through tables (react-native-table-component), and charts (react-native-chart-svg). The raw underlying data may weight approximately 150 kB.
When I put the app in background, it crashes on:
Fatal Exception: java.lang.RuntimeException
android.os.TransactionTooLargeException: data parcel size 852488 bytes
I guess it may be because my Activity (I only have one), uses savedInstanceState
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
_askForOverlayPermission();
}
And when I put my app in the background, it tries to save the state, which is too large. Currently, the state data contains like the id of each 'chunk of data', and then the data corresponding to this chunk (which weight way more). I was wondering if there was a way to say: "If the app is going to go in the background, drop all the data, just keep the ids, so it doesn't crash?
Thank you very much.
Upvotes: 2
Views: 2546
Reputation: 24211
I think the problem is not in your onCreate
function. onCreate
is basically, the lifecycle function which is called when you are initializing an Activity
or starting an Activity
. If you are getting the exception while your application goes into the background, then pay close attention to the onPause
and onDestroy
function. I guess these two are trying to pass some intents to other activities or services which is causing the error.
Hence, you may consider writing some code in your onPause
method of your activity, which will save the ids in the SharedPreferences
or in some database. And then when you are back again and resuming your application again, the onResume
function will be called and retain your ids from the SharedPreferences
or database (wherever you saved the data earlier).
To learn about how you can save the data in SharedPreferences
, here is the developer's documentation. And of course, I would like to suggest you look into the activity lifecycle too.
Upvotes: 1