分享

Android预加载WebView

 飞鹰飞龙飞天 2014-04-14

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.谢谢。

  • for that you have to make your application class and Splash screen class together load Url data in webview in thread itself & set view in finally block ,你必须让你的应用程序类,闪屏类加载URL数据WEBVIEW在finally块中的线程本身设置视图

    import android.app.Activity; import android.view.Window; public class splashScreenWithAct extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mContext=this; getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splashscreen); Thread splashThread = new Thread() { @Override public void run() { try { int waited = 0; while (waited < 800) { sleep(400); waited += 100; } } catch (InterruptedException e) { // do nothing } finally { } } }; splashThread.start(); } } 

    I hope this helpful我希望这有帮助

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多