1 package com.zzw.life; 2 3 import android.app.Activity; 4 import android.os.AsyncTask; 5 import android.os.Bundle; 6 7 public class MainActivity extends Activity { 8 9 @Override 10 protected void onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 setContentView(R.layout.activity_main); 13 14 /* 15 * 运行TestAsyncTask 16 */ 17 new TestAsyncTask().execute(); 18 } 19 20 private class TestAsyncTask extends AsyncTask{ 21 22 //一般用于初始化,首先运行 23 @Override 24 protected void onPreExecute() { 25 // TODO Auto-generated method stub 26 super.onPreExecute(); 27 } 28 //一般处理耗时操作,第二运行 29 @Override 30 protected Object doInBackground(Object... params) { 31 return null; 32 } 33 /* 34 * 一般用于处理UI界面变化,最后运行 35 * result是上面doInBackground返回值 36 */ 37 @Override 38 protected void onPostExecute(Object result) { 39 // TODO Auto-generated method stub 40 super.onPostExecute(result); 41 } 42 43 44 45 } 46 47 48 }
原文:http://www.cnblogs.com/zzw1994/p/4959949.html