首页 > 移动平台 > 详细

Android学习:AsyncTask方案解决UI线程阻塞

时间:2015-02-13 18:39:41      阅读:311      评论:0      收藏:0      [点我收藏+]

post方式能解决UI线程阻塞问题,但是代码的可读性较差。

一:看程序


二:定义AsyncTask
private class testTask extends AsyncTask<String, Void, Integer> {

		protected Integer doInBackground(String... arg0) {
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			int sum = 10;
			return 10;
		}

		protected void onPostExecute(Integer sum) {
			button2.setText("" + sum);
		}

	}


执行task
new testTask().execute();


Android学习:AsyncTask方案解决UI线程阻塞

原文:http://blog.csdn.net/u013628152/article/details/43795581

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!