Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:03:54+00:00 2026-06-11T00:03:54+00:00

I am trying to load a webview in the background using asyntask, while displaying

  • 0

I am trying to load a webview in the background using asyntask, while displaying a splashscreen, when the webview is done loading, i would like the splashscreen to disappear and show the webview. For some reason i am getting a lot of errors in LogCat, when i try to compile and run the code in the emulator.

MainActivity.java

package dk.zerone.vuc;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

public final boolean networkCheck() {
    ConnectivityManager connec =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
    connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) {
        return true;
    } else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  ) {
        return false;
    }
    return false;
}

// The definition of our task class
   private class LoadWebView extends AsyncTask<String, Integer, String> {
   @Override
   protected void onPreExecute() {
      super.onPreExecute();
   }

   protected String doInBackground(String... params) {
      String url = params[0];
       WebView webview = new WebView(MainActivity.this);
       webview.loadUrl(url);
       Log.i("WebView", "doInBackground: Done loading url.");
      return "";
   }

   protected void onPostExecute(String result) {
      super.onPostExecute(result);

      }
   }

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Splash screen */
    setContentView(R.layout.splash);

    if(networkCheck()) {

        //Instantiating the webview, occupies the whole screen.
        //WebView webview = new WebView(this);
        //webview.loadUrl("http://mobil.vucfyn.dk/mobil");

        new LoadWebView().execute("http://mobil.vucfyn.dk/mobil");
        setContentView(R.layout.webview);
        Log.i("WebView", "Execute asyntask");

        /*webview.setWebViewClient(new WebViewClient() {
              @Override
              public void onPageFinished(WebView view, String url) {
                //super.onPageFinished(view, url);
                  Log.i("WebView", "Finished loading.");
                setContentView(R.layout.webview);
              }
            });*/

    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle("Fejl");
        alertDialog.setMessage("Ingen forbindelse til internettet");

        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        alertDialog.show();
    }
  }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
} 
}

Error messages from LogCat:

08-25 11:32:11.544: D/dalvikvm(549): GC_FOR_ALLOC freed 67K, 3% free 10191K/10503K, paused 60ms
08-25 11:32:11.563: I/dalvikvm-heap(549): Grow heap (frag case) to 11.036MB for 1048592-byte allocation
08-25 11:32:11.633: D/dalvikvm(549): GC_CONCURRENT freed 1K, 4% free 11214K/11591K, paused 6ms+3ms
08-25 11:32:11.713: I/WebView(549): SetContentView webview
08-25 11:32:11.733: I/WebView(549): Execute asyntask
08-25 11:32:11.923: D/gralloc_goldfish(549): Emulator without GPU emulation detected.
08-25 11:32:12.593: W/dalvikvm(549): threadid=11: thread exiting with uncaught exception (group=0x409961f8)
08-25 11:32:12.646: E/AndroidRuntime(549): FATAL EXCEPTION: AsyncTask #1
08-25 11:32:12.646: E/AndroidRuntime(549): java.lang.RuntimeException: An error occured while executing doInBackground()
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.os.AsyncTask$3.done(AsyncTask.java:278)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.lang.Thread.run(Thread.java:856)
08-25 11:32:12.646: E/AndroidRuntime(549): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.os.Handler.<init>(Handler.java:121)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.webkit.WebView$PrivateHandler.<init>(WebView.java:8211)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.webkit.WebView.<init>(WebView.java:437)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.webkit.WebView.<init>(WebView.java:1040)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.webkit.WebView.<init>(WebView.java:1029)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.webkit.WebView.<init>(WebView.java:1019)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.webkit.WebView.<init>(WebView.java:1010)
08-25 11:32:12.646: E/AndroidRuntime(549):  at dk.zerone.vuc.MainActivity$LoadWebView.doInBackground(MainActivity.java:42)
08-25 11:32:12.646: E/AndroidRuntime(549):  at dk.zerone.vuc.MainActivity$LoadWebView.doInBackground(MainActivity.java:1)
08-25 11:32:12.646: E/AndroidRuntime(549):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-25 11:32:12.646: E/AndroidRuntime(549):  at java.util.concurrent.FutureTask$Sync.innerRun  (FutureTask.java:305)
08-25 11:32:12.646: E/AndroidRuntime(549):  ... 5 more
08-25 11:32:16.363: I/Process(549): Sending signal. PID: 549 SIG: 9

I don’t know whats wrong, any help is greatly appreciated.

Update:

package dk.zerone.vuc;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

public final boolean networkCheck() {
    ConnectivityManager connec =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
    connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) {
        return true;
    } else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  ) {
        return false;
    }
    return false;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Splash screen */
    setContentView(R.layout.splash);

    if(networkCheck()) {

        String url = "http://mobil.vucfyn.dk/mobil";

        final WebView webview; 
        webview = new WebView(MainActivity.this);

        webview.loadUrl(url); 

        webview.setWebViewClient(new WebViewClient() { 
            @Override 
            public boolean shouldOverrideUrlLoading(WebView view, String url) {     
                //view.loadUrl(url);     
                return false;
            } 

            @Override 
            public void onPageFinished(WebView view, String url) { 
                super.onPageFinished(view, url); 
                setContentView(webview);
             } 
        });

    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle("Fejl");
        alertDialog.setMessage("Ingen forbindelse til internettet");

        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        alertDialog.show();
    }
  }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
} 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:03:56+00:00Added an answer on June 11, 2026 at 12:03 am

    Enabling JavaScript did the trick.

        webview.getSettings().setJavaScriptEnabled(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load a html file in my webview using this codes. but
I am trying to load a flash in a webview using the codes below
I have WebView in myLayout and I am trying to load html string like
While trying to load a Bitmap onto a SWFLoader the Event.COMPLETE event is not
Im trying to load a image at runtime in WPF using the following code
I have a webview and am trying to load simple UTF-8 text into it.
I am trying to setup a application to load URL in Webview and then
I'm receiving an error when trying to load a URL in a WebView. What
I'm trying to load the parsed html data from an rss feed using a
I am trying to load a website using Phonegap on Android with the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.