setRetainInstance is deprecated. What alternative?
I have a lot of fragments with many complicated object variables inside them.
Today I only have one line of code: setRetainInstance.
Full code example is below:
public class MyFragment extends Fragment{
private MyComplicatedCustomClass1 object1;
private MyComplicatedCustomClass2 object2;
private MyComplicatedCustomClass3 object3;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
}
This is more than enough to forget about saving and restoring my objects when changing the configuration (for example, when changing the screen rotation).
What should I change in my code for replacing setRetainInstance?
Please give me a short code example, if possible.
P.S.
ATTENTION: I can read the documentation - so please don't answer in a Google-style manner: "ViewModel is the best... google recommend... and bla-bla...". And please don't copy/paste articles from Google documentation - I can view it myself.
If you have a concrete working code solution - I will very appreciate it.