-1

I have a navigation activity with 10 fragments consisting of WebView.

Now when I enter/transits from "A" fragment to "B" and later onBackPress it transits back to "A" but it reloads again.

I wanted to come back to the same position where "A" was left.

André Sousa
  • 1,692
  • 1
  • 12
  • 23
  • 2
    If this is related to the question you asked earlier today, it is because you are removing the fragment from the backstack. Either way, you should post your code so we can get a better idea of what you are doing. – Chris Stillwell Nov 07 '18 at 21:18
  • in onpause() method save your position of movie or somthing else and in onresume set again variable and position for more detail read this doc https://www.journaldev.com/9266/android-fragment-lifecycle – Ardalan Sajedi Nov 07 '18 at 21:32
  • maybe post your code it will help us to solve the problem – Ticherhaz FreePalestine Nov 08 '18 at 01:13

1 Answers1

0

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.

N. Matic
  • 213
  • 1
  • 8