问题
I want to preload the web URL before activity launch. So can I instantiate the fragment under application context ?
EDIT : - creating webview inside Application subclass and retrieving it in the activity .but unable to use it because of different contexts. < This happened if using support fragment library> - using service component to create webview and retrieving it in activity. same context issue as service is started under application context . < This happened if using support fragment library>
UPDATE : I am able create a webview object under application context and retrieving it in fragments as and when needed in any activities. it is working fine on Android OS 4.0 and up . I have tested on Android OS 4 and up. Just in case if any one needs
回答1:
You could handle an WebViewClient listener do get when your page was completely loaded in an WebView and after that add/show your fragment.
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
Documentation explanation:
Notify the host application that a page has finished loading. This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet. To get the notification for the new Picture, use onNewPicture(WebView, Picture).
See more at: onPageFinished (WebView view, String url)
回答2:
I instantiated Webview under Application context and called this view inside a fragment after activity launch. it seems to be working fine.
来源:https://stackoverflow.com/questions/23524211/android-webview-application-context