当我在DDMS中使用AsyncTasks检查时,线程在onPostExecute()方法之后作为等待线程保留在内存中,这是正常的吗?这是一个简化的Activity,它可以重现我的问题:
package com.example.async; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; public class ASyncTaskExampleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new ExampleAsyncTask().execute(); } private class ExampleAsyncTask extends AsyncTask<Void,Void,Void> { @Override protected Void doInBackground(Void... params) { for (int i =0; i<50000;i++){ int j=i*2; } return null; } protected void onPostExecute(Void result) { Log.d("Test","End onPostExecute"); } }
}