Since the deprecation of onRetainNonConfigurationInstance
I have been leveraging the framework more and more for Configuration changes. Since I use the ViewPager to hold my main Fragments I cannot use setRetainInstance
, which limits my Configuration changes to use onSaveInstanceState like a standard Activity or View would.
It is working perfectly without any problems but I am at the moment passing a quite sizable Serializable dataset through it that makes me want to get the communities input on whether or not it is a good idea.
tl;dr : Does onSaveInstanceState have a size limitation on what you pass through it?
The onSaveInstanceState() method allows you to add key/value pairs to the outState of the app. Then the onRestoreInstanceState() method will allow you to retrieve the value and set it back to the variable from which it was originally collected.
Basically, onSaveInstanceState is used for the scenario where Android kills off your activity to reclaim memory. In that scenario, the OS will keep a record of your activity's presence, in case the user returns to it, and it will then pass the Bundle from onSaveInstanceState to your onCreate method.
1 Answer. Show activity on this post. You can replace above with the data you want to save and then re-populate your views like RecyclerView etc with the data you saved in the savedInstance as key-value pair. Just keep in mind that the Bundle is not meant to store Large amount of data.
Various Android system operations can affect the state of your fragment. To ensure the user's state is saved, the Android framework automatically saves and restores the fragments and the back stack. Therefore, you need to ensure that any data in your fragment is saved and restored as well.
It would be helpful to say something more than "quite sizeable." :)
This data goes through an IPC, and the IPC limit is about 1MB. You want to keep your marshalled size significantly smaller than that; 100K is probably a good maximum. And really you want to keep this as small as possible (think about what you put in there and don't waste space), because this data will have to be held by the system in RAM even when your own process is killed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With