WebView getting created multiple times (on each link click)
I initialize a WebVi开发者_JS百科ew object in my activity, load the URL and if the URL loaded correctly, I start another activity that sets this web view as its content view.
Code where WebView is constructed:
webView = new MyWebView( getApplicationContext(), Settings.this, AsyncWebConnect.this);
webView.loadUrl(url);
Once the web view has loaded the URL (I get this info through a callback), I initialize the second activity which will show the web view.
((MyApplication)getApplication()).setWebView(webView);
startActivity(new Intent(getApplicationContext(), WebActivity.class));
And in the WebActivity's onCreate, I retrieve this web view and set it as content:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final WebView engine = ((MyApplication)getApplication()).getWebView();
setContentView(engine);
}
The problem is, each time I click on a link within the loaded page, the activity is created again. Has someone see this earlier? Please let know if there's something wrong that's been done here.
I think you have to intercept the page loads like in this example
精彩评论