generally speaking you can't/shouldn't.
# android
a
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
p
If it wasnt like that you could just create the fragment with the arguments in it's constructor
a
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
j
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.
a
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.