Skip to content Skip to sidebar Skip to footer

How To Prevent Refreshing Of Webview In Navigation Drawer

From a while i had been using viewpager to display webview pages in activity, but now i have change from viewpager to navigation drawer with RecyclerView, to display webview, i hav

Solution 1:

Are you saying that you want to restore the same fragment? This is from developer.android.com

FragmentTransactiontransaction= getSupportFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment,// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();

This enables the back navigation button to restore the same fragment that already loaded the webview. You are creating a new one each time in the switch statement.

Once you get the back button working how you want it you can easily learn how to manually pull the specific fragment off of the stack.

Edit:

I do not think you are refreshing the webview. You are creating a new fragment each time you select an item by calling the empty constructor. You need to only create each fragment one time and then use the same instance of that fragment when you go back to that webview. Using the back stack will enable it to stay loaded while you leave the application and come back to it later.

Also try using the static method YourFragment.newInstance(params) which returns a new instance of YourFragment. Do this instead of the empty constructor, as that is considered incorrect practice.

Post a Comment for "How To Prevent Refreshing Of Webview In Navigation Drawer"