I’d like to start a WebView from my AsyncTask but it doesn’t seem to run. This is what my onPostExecute method looks like:
public class Viewer extends AsyncTask<URI, Integer, URI> {
private Activity objContext = null;
public Viewer(Activity objContext) {
this.objContext = objContext;
}
protected void onPostExecute(URI uriWebpage) {
WebView wbvBrowser = new WebView(this.objContext);
wbvBrowser.getSettings().setBuiltInZoomControls(true);
wbvBrowser.getSettings().setJavaScriptEnabled(true);
wbvBrowser.loadUrl(uriWebpage.toString());
}
}
My task is used by two activities in my application and therefore my global objContext variable is of type Activity. If I change the type of my objContext variable to the name of the calling class, it works fine but then I can’t instantiate my task from the other calling class. I instantiate my task like this.
Viewer mytask = new Viewer(this);
How can I solve this?
I have solved the issue. It has nothing to do with the use of
ActivityorContext. Both work just fine. Some URLs don’t seem to load theWebView. I changed the URL of theWebViewto point to a site like Google and it worked just fine. Seems like if the URL is incorrect, theWebViewdoesn’t throw an exception but doesn’t open up either.