我有一个FragmentPagerAdapter,用于显示大约6个选项卡,所有选项卡都从Web服务器加载数据.其中一个选项卡包含一个从我的服务器加载图像的WebView.生成映像的服务器端成本很高,因此我希望减少重新加载WebView的调用次数.对于非web视图选项卡,我已经能够拯救我的国家(对于那些,只是一个简单的数组),并恢复他们的标签得到刷卡通过.
问题:
考虑的解决方案:
听起来像WebView.saveState()的旧行为本来就是完美的......
我是 Android 应用程序开发的新手,需要一些帮助。我注意到当我WebView
使用导航选项卡尝试我的片段时,它们保持它们的状态很好,但是当我切换到使用导航抽屉时,每次我点击一个抽屉项目,然后点击我已经加载的抽屉项目回到那个抽屉项目,它只是重新加载WebView
.
主要活动代码:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
NavigationView navigationView = null;
Toolbar toolbar = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Set the fragment initially
MainFragment fragment = new MainFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
//How to change elements in the …
Run Code Online (Sandbox Code Playgroud)