If you wanna do it properly, use ViewModel
, here's a guide.
If that is too complicated, you can imitate a ViewModel by saving data somewhere in your activity during a fragments onPause()
. For example:
boolean alreadyLoaded = true;
boolean btn1Shown = true;
String editText1Text = editText1.getText().toString;
And add to your onCreateView()
if (alreadyLoaded) {
if (btn1Shown)
btn1.setVisibility(View.VISIBLE);
editText1.setText(editText1Text);
This will probably require some interface, or public activity methods, and thats why ViewModel exists so that you don't have to do those things.