asynctask
我对on有问题,doInBackground
因为我在以下代码中遇到运行时错误:
ConnectivityManager connectivity = (ConnectivityManager) content.getSystemService(Context.CONNECTIVITY_SERVICE);
(((我想在 a 中查看图像,inamgeview
但首先检查连接是否处于活动状态,这些操作在不扩展活动的单独类中执行)):
这是主要活动:
public class TelevideoInternationalActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
String loc = "Nazionale";
static String home_page = "http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.png";
WorkAsyncIta wai = new WorkAsyncIta();
static String but = "";
Context content;
/************DECLARES**************/
RelativeLayout relativeLayout1;
ImageView imgpag;
ProgressBar probar;
/**********INITIALIZES**************/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgpag = (ImageView)findViewById (R.id.imgpag);
relativeLayout1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
probar = (ProgressBar) findViewById (R.id.probar);
wai.execute("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.png" );
}
private class WorkAsyncIta extends AsyncTask<String, Void, Bitmap>
{
@Override
protected void onPreExecute()
{
probar.setVisibility(0);
}
@Override
protected Bitmap doInBackground(String... url) {
return ItaliaTelevideo.setHomePage(url[0], content);
}
@Override
protected void onPostExecute(Bitmap result) {
probar.setVisibility(1);
imgpag.setImageBitmap(result);
imgpag.setScaleType(ScaleType.FIT_XY);
}
}
}
我已经纠正了错误,但我现在在调试视图中看到了这一点:
Thread [<17> AsyncTask #1] (Stepping)
ThreadPoolExecutor$Worker.run() line: 672
Thread.run() line: 1060
imageview
如果我触摸屏幕返回,则不显示任何内容:
Thread [<3> main] (Suspended (exception IllegalStateException))
ViewRoot.handleMessage (Message) line: 1704
ViewRoot (Handler). DispatchMessage (Message) line: 99
Looper.loop () line: 123
ActivityThread.main (String []) line: 4203
Method.invokeNative (Object, Object [], Class, Class [], Class, int, boolean) line: not available [native method]
Method.invoke (Object, Object ...) line: 521
ZygoteInit MethodAndArgsCaller.run $ () line: 791
ZygoteInit.main (String []) line: 549
NativeStart.main (String []) line: not available [native method]