# android

Adam Powell

11/19/2019, 5:06 PM
generally speaking you can't/shouldn't.
👍 4
oops, should have threaded
The FragmentManager will recreate your fragment instances for you without your code necessarily running again

Paul Woitaschek

11/19/2019, 5:41 PM
If it wasnt like that you could just create the fragment with the arguments in it's constructor

Adam Powell

11/19/2019, 8:26 PM
Yes, and you can install a fragment factory to do that in newer versions of the fragment lib, but you still end up with a chicken and egg problem of needing to recreate a potentially complex lambda capture from a restarted process


11/20/2019, 7:14 AM
I'm not gonna argue about ethics, but what you could still do is serialize the callback interface object and pass it to the factory as is and just make sure every object within implements a serializable.

Adam Powell

11/20/2019, 1:29 PM
No ethics involved, just a question of whether this will make things a lot harder for yourself down the road. 🙂 Android enforces a limit on the size of your saved state in the form of the binder transaction size, and if you start marking things serializable to do things this way you'll probably hit it sooner or later and have a very difficult time sorting it out.