Android:使用Widget在主线程上建立网络

时间:2013-01-17 21:14:06

标签: android multithreading exception networking widget

我制作了一个简单的小部件(AppWidgetProvider)。要加载其内容,它需要连接到互联网(JSoup是惊人的)。显然,我有一个很棒的NetworkOnMainThreadException。我试图做AsyncTask,但是Eclipse正在向我喊No enclosing instance of type WidgetClass is accessible. Must qualify the allocation with an enclosing instance of type WidgetClass (e.g. x.new A() where x is an instance of WidgetClass).,所以我无法运行它。

我怎么解决?

谢谢!

1 个答案:

答案 0 :(得分:0)

也许你试图在声明区域中调用myAsync()。execute()?

public class MyActivity extends Activity {
    new myAsync().execute();//wouldn't work
}