18

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?

HandlerExploit
  • 8,131
  • 4
  • 31
  • 50
  • I think it does not. Probably it uses `SharedPreferences` -- I guess that. –  Mar 29 '12 at 01:05
  • "Since I use the ViewPager to hold my main Fragments I cannot use setRetainInstance" -- Why do you think you cannot use `setRetainInstance()` with fragments in a `ViewPager`? I cannot find any place that cites this limitation. Got a link? Thanks! – CommonsWare Mar 31 '12 at 10:19
  • It simply does not work, it is probably a bug. I have tried with both the `FragmentPagerAdapter` and `FragmentStatePagerAdapter` and neither resulted in the Fragments working correctly with `setRetainInstance()`. When I moved them from the `ViewPager` to a standard switch similar to (see below) everything worked correctly. http://developer.android.com/resources/samples/Support13Demos/src/com/example/android/supportv13/app/ActionBarTabsPager.html – HandlerExploit Mar 31 '12 at 13:30

2 Answers2

22

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.

hackbod
  • 90,665
  • 16
  • 140
  • 154
-1

The limit is the memory limit and since you are not having OutOfMemory errors, that should be fine.

Just make sure to not have any View or Context on the passing object because this can cause the use of memory to grow rapidly if the user changes orientation constantly.

Marcio Covre
  • 4,556
  • 2
  • 22
  • 24
  • How is it held in memory if the application is recycled? This information is persisten even then so I know it cannot be held any memory that would depend on the application so of course OutOfMemoryErrors would not occur on the application itself. And I explicitly stated I was passing Serializable objects, it is impossible to pass a View or a Context through that. But if you did pass one through onRetainNonConfigurationInstance it would leak the entire Activity so yes it would eventually run out of memory on Configuration changes in that scenario. – HandlerExploit Mar 29 '12 at 21:26