代码如下:
public class AsyncTastTest extends Activity {
private static final String TAG = "AsyncTastTest";
private TextView textview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textview = (TextView)findViewById(R.id.textview);
        
        new MyAsyncTast().execute(new String[]{});
    }
    
    class MyAsyncTast extends AsyncTask<String, Integer, Long>{
@Override
protected Long doInBackground(String... params) {
Log.v(TAG,"doInBackground:" +System.currentTimeMillis());
long result =  0;
for(int i = 0;i<100000000; i++){
if(i%1000000==0){
publishProgress(new Integer[]{i/1000000});
}
result = result + i;
}
return result;
} @Override
protected void onCancelled() {
super.onCancelled();
} @Override
protected void onPostExecute(Long result) {
super.onPostExecute(result);
Log.v(TAG,"onPostExecute:" +System.currentTimeMillis());
Log.v(TAG,"result:" +result);
textview.setText("completed");

} @Override
protected void onPreExecute() {
super.onPreExecute();
textview.setText("running");
Log.v(TAG,"onPreExecute:" +System.currentTimeMillis());
} @Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
textview.setText("progress" + values[0]);
Log.v(TAG,"onProgressUpdate:" +System.currentTimeMillis());
}
    }
}