Issue
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?
Solution
I have solved the issue. It has nothing to do with the use of Activity
or Context
. Both work just fine. Some URLs don't seem to load the WebView
. I changed the URL of the WebView
to point to a site like Google and it worked just fine. Seems like if the URL is incorrect, the WebView
doesn't throw an exception but doesn't open up either.
Answered By - Mridang Agarwalla
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.