In my app if I go from the first fragment to the third one, and I go back to the first one the webview restarts the page, how do I solve the problem?
obs: I'm a beginner so if possible have a little patience. enter code here
> package com.cartolafcmidia.cartolafcnew;
>
> import android.support.v4.view.ViewPager; import
> android.support.v7.app.AppCompatActivity; import android.os.Bundle;
> import android.webkit.WebSettings; import android.webkit.WebView;
> import android.webkit.WebViewClient; import
> com.cartolafcmidia.cartolafcnew.R; import
> com.cartolafcmidia.cartolafcnew.SiteFragment; import
> com.ogaclejapan.smarttablayout.SmartTabLayout; import
> com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
> import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
>
> public class MainActivity extends AppCompatActivity {
>
> private ViewPager ViewPager;
> private SmartTabLayout smartTabLayout;
>
> FragmentX fragmentX;
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
>
>
> setContentView(R.layout.activity_main);
> fragmentX = new FragmentX();
> SiteFragment fragmentoSite = new SiteFragment();
> TwitterFragment fragmentoTwitter = new TwitterFragment();
> InstaFragment fragmentoInstagram = new InstaFragment();
> FaceFragment fragmentoFacebook = new FaceFragment();
>
>
> ViewPager = findViewById(R.id.viewPager);
>
>
>
> smartTabLayout=findViewById(R.id.viewPagerTab);
> getSupportActionBar().setElevation(0);
> getSupportActionBar().setTitle("CartolaFC MÍDIAS");
>
> //Configurar Abas
> FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
> getSupportFragmentManager(),
> FragmentPagerItems.with(this)
> .add("Site", SiteFragment.class)
> .add("Twitter", TwitterFragment.class)
> .add("Instagram", InstaFragment.class)
> .add("Facebook", FaceFragment.class)
>
> .create()
> ); ViewPager.setAdapter(adapter); smartTabLayout.setViewPager(ViewPager);
>
>
>
> } }
One of the fragments:
package com.cartolafcmidia.cartolafcnew;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
/**
* A simple {@link Fragment} subclass.
*/
public class SiteFragment extends Fragment {
public SiteFragment() {
// Required empty public constructor
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
setRetainInstance(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ) {
// Inflate the layout for this fragment
View v =inflater.inflate(R.layout.fragment_site2, container, false);
WebView webView =(WebView)v.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
setRetainInstance(true);
setReturnTransition(true);
//Desempenho
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setAppCacheEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl("http://globoesporte.globo.com/cartola-fc/");
setRetainInstance(true);
return v;
}
}