Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preloading web page in Android (using WebView?)

I want to pre load a web page in Android. The web page contains both text and graphical elements. The web page will be displayed in the future in an Activity which has not been created yet.

As far I understand it a WebView for example has to be tied to an Activity, thus it's not possible to use a WebView for this task.

Anyone got any suggestions which does not involve parsing the html page and downloading all the elements "manually"?

like image 681
Henrik Avatar asked Feb 17 '13 18:02

Henrik


People also ask

What is the use of WebView in android?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.

How do I cache WebView?

This example demonstrate about How to enable app cache for webview in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I enable Javascript on Android WebView?

Android App Development for Beginners This example demonstrate about How to enable webview java script in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

Which browser is used in Android WebView?

Chrome, Google's ubiquitous browser, powers Android System WebView. The Android System WebView app is typically pre-installed on most Android smartphones. That way, every developer that resorts to using it to render internet content inside their app can do so without warning about compatibility issues.


1 Answers

According to android's documenation: For obvious security reasons, your application has its own cache, cookie store etc.—it does not share the Browser application's data.

So we can make use of the above info in a smart way by doing this:

  • Whenever you want to start loading your website, create a new WebView object and request the url from it. the code will look something like this:

     WebView view = new WebView(context);
     view.loadUrl(myBigWebSite);
    
  • Android will cache that webview data and when you request loadUrl from another activity it should be already loaded.

     // in your WebView activity
     myWebView.loadUrl(myBigWebSite);
    

For more about webViews visit the documentations page : WebView doc

like image 91
Mr.Me Avatar answered Oct 01 '22 04:10

Mr.Me