无法从AsyncTask的开始的WebView

无法从AsyncTask的开始的WebView

本文介绍了无法从AsyncTask的开始的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始一个的WebView 从我的AsyncTask ,但它似乎没有运行。这是我的 onPostExecute 方法看起来是这样的:

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());
      }

  }

我的任务就是在我的应用程序使用的两种活动,因此我的全球 objContext 变量的类型活动的。如果我改变我的 objContext 变量的类型调用类的名称,它工作正常,但我不能实例从另一个调用类我的任务。我实例化我的任务是这样的。

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?

推荐答案

我已经解决了这个问题。它无关,与使用活动的上下文。这两个工作得很好。一些网址似乎不加载的WebView 。我改变了的WebView 的URL指向一个像谷歌网站和它的工作就好了。好像如果该URL不正确,的WebView 不抛出异常,但不要么打开。

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.

这篇关于无法从AsyncTask的开始的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:24