I have an app with a splash-screen which after a few seconds opens up the main activity that has a WebView.我有一个应用程序的一个启动画面,几秒钟后打开了,有一个webview的主要活动。 The problem is that, only then, does the main activity start to load the URL, which sometimes take several seconds.现在的问题是,只有到那时,没有主要的活动开始加载URL,有时需要几秒钟。 It seems silly for the double wait.看来愚蠢的双待。 However, my attempts to pre-load the WebView have been less then successful.不过,我尝试预加载的WebView已经不到成功。
The essence of the issue is that the splash screen and main activity are two different activities and the WebView is resource bound (layout) to the main activity.本质的问题是,闪屏和主要活动是两个不同的活动和WebView是资源约束(布局)的主要活动。Copying the WebView (webview2=webview1) doesn't work, not surprisingly.不复制的WebView(webview2 webview1)的工作,这并不奇怪。
Suggestions?建议吗?
Follow these steps..请按照以下步骤..
1) set splash layout on your screen. 1)设置启动布局在屏幕上。
2) start a new thread, in this thread inflate a layout that contains webview. 2)启动一个新的线程,在这个线程膨胀的布局包含WEBVIEW。
3) Load url in webView. 3)负载url中的WebView。 Set webview Client to webview to know when your page loading completes. There is a quick example . WEBVIEW客户端设置WEBVIEW知道你的页面加载完成时, 有一个简单的例子 。 override onPageFinished.覆盖onPageFinished。
4) Now break the thread and pass this inflated view to next activity, and set it to setContentView(inflatedView); 4)打破线程,并通过膨胀的到下一个活动,将其设置为的setContentView(inflatedView);
Thanks.谢谢。