1

I want to run my webview in android behind the splash screen and bring up the WebView once it has completed loading the page.

Bellow is an extract of the code I have:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    setContentView(R.layout.main);
    mWebView = (WebView) findViewById(R.id.webview);    
    mWebView.getSettings().setJavaScriptEnabled(true);    
    mWebView.loadUrl(url);
    mWebView.setWebViewClient(new webviewclient());
   }

public class webviewclient extends WebViewClient {    
@Override    
public boolean shouldOverrideUrlLoading(WebView view, String url) {        
    view.loadUrl(url); 
    return true;    
    }
}

Currently the splash screen appears for a split second and then the WebView appears and starts loading the page.

Any suggestions on how to convert this to Asynchronous?

Beanonymous
  • 95
  • 2
  • 9

2 Answers2

1

When ever you want to do anything asynchronously Android AsycTask is your best bet for and easy starting point. http://developer.android.com/reference/android/os/AsyncTask.html

Your gonna want to go about it by setting the splash screen in your onCreate, the execute the asyncTask to load the webview. Then in you onPostExecute you can setContentView to the webview.

Hope that helps

Stevy888
  • 364
  • 1
  • 8
0

This may not be the CLEANEST answer, but you could have an image view on top of your WebView that essentially displays the same splash image, the perform progress checking for you WebView, and only dismiss the ImageView from screen when your WebView reaches 100%

Here is a link to progress checking / implementation: Android WebView progress bar

Community
  • 1
  • 1
trumpetlicks
  • 7,033
  • 2
  • 19
  • 33
  • trumpetlicks your solution is the only one that seems to work on android without any execution errors. For those out there with the same kind of issue I would suggest you use something similar to the code bellow. http://relentlesshosting.com.au/screenshot/1jNx6K.jpg – Beanonymous Jul 02 '12 at 14:12
  • @Beanonymous, image link is now broken. – Chad Dec 21 '14 at 21:52