WebViewPool, Last html page show before new url when reuse WebView from WebViewPoolAndroid App development - WebView is not workingAndroid - setting WebViewClient causes NullPointerException in AsyncTaskandroid: camera onPause/onResume issueAndroid: BatteryLevel widget not updatingAndroid webview - Enable Private BrowsingWhy does my exception handler not trap Android SQLite insert error?setText on button from another activity androidSaving ToggleButton state in ListView by using SharedPreferencesUndo/Redo not working in android CanvasHow to implement parcelable with my custom class containing Hashmap and SparseArray?
Why does a simple loop result in ASYNC_NETWORK_IO waits?
How much character growth crosses the line into breaking the character
Hero deduces identity of a killer
Why Shazam when there is already Superman?
Creepy dinosaur pc game identification
Does Doodling or Improvising on the Piano Have Any Benefits?
What are the advantages of simplicial model categories over non-simplicial ones?
PTIJ: Haman's bad computer
Is aluminum electrical wire used on aircraft?
Can a Canadian Travel to the USA twice, less than 180 days each time?
What is the highest possible scrabble score for placing a single tile
Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
Recommended PCB layout understanding - ADM2572 datasheet
Multiplicative persistence
It grows, but water kills it
Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?
Why would a new[] expression ever invoke a destructor?
Need help understanding what a natural log transformation is actually doing and why specific transformations are required for linear regression
What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?
Using substitution ciphers to generate new alphabets in a novel
Redundant comparison & "if" before assignment
How does a computer interpret real numbers?
I'm the sea and the sun
WebViewPool, Last html page show before new url when reuse WebView from WebViewPool
Android App development - WebView is not workingAndroid - setting WebViewClient causes NullPointerException in AsyncTaskandroid: camera onPause/onResume issueAndroid: BatteryLevel widget not updatingAndroid webview - Enable Private BrowsingWhy does my exception handler not trap Android SQLite insert error?setText on button from another activity androidSaving ToggleButton state in ListView by using SharedPreferencesUndo/Redo not working in android CanvasHow to implement parcelable with my custom class containing Hashmap and SparseArray?
There is a WebViewPool,when Activity/Fragment is destoryed,webview will be reset and add to the WebViewPool.
The following is the code of WebViewPool:
public class WebViewPool
private static volatile WebViewPool sINSTANCE;
private int mMaxSize;
private List<WebView> mAvailableList;
private List<WebView> mInUsedList;
private IWebViewPoolFactory mFactory;
private WebViewPool()
public static WebViewPool getInstance()
if (sINSTANCE == null)
synchronized (WebViewPool.class)
if (sINSTANCE == null)
sINSTANCE = new WebViewPool();
return sINSTANCE;
public void init(IWebViewPoolFactory factory,boolean lazy)
init(2, factory,lazy);
public void init(int maxSize, IWebViewPoolFactory factory,boolean lazy)
mMaxSize = maxSize;
mFactory = factory;
mAvailableList = new ArrayList<>(maxSize);
mInUsedList = new ArrayList<>(maxSize);
if (!lazy)
create();
private synchronized void create()
if (mFactory == null)
return;
for (int i = 0; i < mMaxSize; i++)
WebView webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
mAvailableList.add(webView);
/**
* get webview form pool
* @param context
* @return
*/
public synchronized WebView getWebView(Context context)
if(!(context instanceof Activity))
throw new IllegalStateException("Context must be Activity");
WebView webView = null;
if (mAvailableList.size() > 0)
webView = mAvailableList.remove(0);
else
if (mFactory != null)
webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
if (webView != null)
((MutableContextWrapper) webView.getContext()).setBaseContext(context);
mInUsedList.add(webView);
return webView;
/**
* reset/destroy webview when activity/fragemnt is destroyed
* @param webView
*/
public synchronized void restWebView(WebView webView)
if (webView == null
the following is some code of reset
function:
public void reset(WebView webView)
if(webView==null)
return;
ViewParent viewParent = webView.getParent();
if (viewParent!=null)
((ViewGroup)viewParent).removeView(webView);
webView.stopLoading();
webView.clearCache(false);
webView.loadUrl("about:blank");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable()
@Override
public void run()
webView.clearHistory();
, 1000);
But when reuse the webview,last html page show first before new url sometimes.It doesn't happened everytime. I searched in Google, but not work.Does anyone know the reason? Thank you!
android webview android-webview
add a comment |
There is a WebViewPool,when Activity/Fragment is destoryed,webview will be reset and add to the WebViewPool.
The following is the code of WebViewPool:
public class WebViewPool
private static volatile WebViewPool sINSTANCE;
private int mMaxSize;
private List<WebView> mAvailableList;
private List<WebView> mInUsedList;
private IWebViewPoolFactory mFactory;
private WebViewPool()
public static WebViewPool getInstance()
if (sINSTANCE == null)
synchronized (WebViewPool.class)
if (sINSTANCE == null)
sINSTANCE = new WebViewPool();
return sINSTANCE;
public void init(IWebViewPoolFactory factory,boolean lazy)
init(2, factory,lazy);
public void init(int maxSize, IWebViewPoolFactory factory,boolean lazy)
mMaxSize = maxSize;
mFactory = factory;
mAvailableList = new ArrayList<>(maxSize);
mInUsedList = new ArrayList<>(maxSize);
if (!lazy)
create();
private synchronized void create()
if (mFactory == null)
return;
for (int i = 0; i < mMaxSize; i++)
WebView webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
mAvailableList.add(webView);
/**
* get webview form pool
* @param context
* @return
*/
public synchronized WebView getWebView(Context context)
if(!(context instanceof Activity))
throw new IllegalStateException("Context must be Activity");
WebView webView = null;
if (mAvailableList.size() > 0)
webView = mAvailableList.remove(0);
else
if (mFactory != null)
webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
if (webView != null)
((MutableContextWrapper) webView.getContext()).setBaseContext(context);
mInUsedList.add(webView);
return webView;
/**
* reset/destroy webview when activity/fragemnt is destroyed
* @param webView
*/
public synchronized void restWebView(WebView webView)
if (webView == null
the following is some code of reset
function:
public void reset(WebView webView)
if(webView==null)
return;
ViewParent viewParent = webView.getParent();
if (viewParent!=null)
((ViewGroup)viewParent).removeView(webView);
webView.stopLoading();
webView.clearCache(false);
webView.loadUrl("about:blank");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable()
@Override
public void run()
webView.clearHistory();
, 1000);
But when reuse the webview,last html page show first before new url sometimes.It doesn't happened everytime. I searched in Google, but not work.Does anyone know the reason? Thank you!
android webview android-webview
add a comment |
There is a WebViewPool,when Activity/Fragment is destoryed,webview will be reset and add to the WebViewPool.
The following is the code of WebViewPool:
public class WebViewPool
private static volatile WebViewPool sINSTANCE;
private int mMaxSize;
private List<WebView> mAvailableList;
private List<WebView> mInUsedList;
private IWebViewPoolFactory mFactory;
private WebViewPool()
public static WebViewPool getInstance()
if (sINSTANCE == null)
synchronized (WebViewPool.class)
if (sINSTANCE == null)
sINSTANCE = new WebViewPool();
return sINSTANCE;
public void init(IWebViewPoolFactory factory,boolean lazy)
init(2, factory,lazy);
public void init(int maxSize, IWebViewPoolFactory factory,boolean lazy)
mMaxSize = maxSize;
mFactory = factory;
mAvailableList = new ArrayList<>(maxSize);
mInUsedList = new ArrayList<>(maxSize);
if (!lazy)
create();
private synchronized void create()
if (mFactory == null)
return;
for (int i = 0; i < mMaxSize; i++)
WebView webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
mAvailableList.add(webView);
/**
* get webview form pool
* @param context
* @return
*/
public synchronized WebView getWebView(Context context)
if(!(context instanceof Activity))
throw new IllegalStateException("Context must be Activity");
WebView webView = null;
if (mAvailableList.size() > 0)
webView = mAvailableList.remove(0);
else
if (mFactory != null)
webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
if (webView != null)
((MutableContextWrapper) webView.getContext()).setBaseContext(context);
mInUsedList.add(webView);
return webView;
/**
* reset/destroy webview when activity/fragemnt is destroyed
* @param webView
*/
public synchronized void restWebView(WebView webView)
if (webView == null
the following is some code of reset
function:
public void reset(WebView webView)
if(webView==null)
return;
ViewParent viewParent = webView.getParent();
if (viewParent!=null)
((ViewGroup)viewParent).removeView(webView);
webView.stopLoading();
webView.clearCache(false);
webView.loadUrl("about:blank");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable()
@Override
public void run()
webView.clearHistory();
, 1000);
But when reuse the webview,last html page show first before new url sometimes.It doesn't happened everytime. I searched in Google, but not work.Does anyone know the reason? Thank you!
android webview android-webview
There is a WebViewPool,when Activity/Fragment is destoryed,webview will be reset and add to the WebViewPool.
The following is the code of WebViewPool:
public class WebViewPool
private static volatile WebViewPool sINSTANCE;
private int mMaxSize;
private List<WebView> mAvailableList;
private List<WebView> mInUsedList;
private IWebViewPoolFactory mFactory;
private WebViewPool()
public static WebViewPool getInstance()
if (sINSTANCE == null)
synchronized (WebViewPool.class)
if (sINSTANCE == null)
sINSTANCE = new WebViewPool();
return sINSTANCE;
public void init(IWebViewPoolFactory factory,boolean lazy)
init(2, factory,lazy);
public void init(int maxSize, IWebViewPoolFactory factory,boolean lazy)
mMaxSize = maxSize;
mFactory = factory;
mAvailableList = new ArrayList<>(maxSize);
mInUsedList = new ArrayList<>(maxSize);
if (!lazy)
create();
private synchronized void create()
if (mFactory == null)
return;
for (int i = 0; i < mMaxSize; i++)
WebView webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
mAvailableList.add(webView);
/**
* get webview form pool
* @param context
* @return
*/
public synchronized WebView getWebView(Context context)
if(!(context instanceof Activity))
throw new IllegalStateException("Context must be Activity");
WebView webView = null;
if (mAvailableList.size() > 0)
webView = mAvailableList.remove(0);
else
if (mFactory != null)
webView = mFactory.create(new MutableContextWrapper(APP.getApplicationContext()));
if (webView != null)
((MutableContextWrapper) webView.getContext()).setBaseContext(context);
mInUsedList.add(webView);
return webView;
/**
* reset/destroy webview when activity/fragemnt is destroyed
* @param webView
*/
public synchronized void restWebView(WebView webView)
if (webView == null
the following is some code of reset
function:
public void reset(WebView webView)
if(webView==null)
return;
ViewParent viewParent = webView.getParent();
if (viewParent!=null)
((ViewGroup)viewParent).removeView(webView);
webView.stopLoading();
webView.clearCache(false);
webView.loadUrl("about:blank");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable()
@Override
public void run()
webView.clearHistory();
, 1000);
But when reuse the webview,last html page show first before new url sometimes.It doesn't happened everytime. I searched in Google, but not work.Does anyone know the reason? Thank you!
android webview android-webview
android webview android-webview
edited yesterday
zys
asked yesterday
zyszys
69921332
69921332
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280539%2fwebviewpool-last-html-page-show-before-new-url-when-reuse-webview-from-webviewp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280539%2fwebviewpool-last-html-page-show-before-new-url-when-reuse-webview-from-webviewp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown