2
DalvikVM[localhost:8604]    
Thread [<1> main] (Running) 
Thread [<7> Binder Thread #2] (Running) 
Thread [<6> Binder Thread #1] (Running) 
Thread [<8> AsyncTask #1] (Running) 
Thread [<9> Binder Thread #3] (Running) 
Thread [<10> Binder Thread #4] (Running)    
Thread [<11> AsyncTask #2] (Running)    
Thread [<12> AsyncTask #3] (Running)    

While running my application i have seen this in the debug window. I am wondering is this correct? Should there be these many tasks running. For example Thread [<8> AsyncTask #1] (Running) This task downloads a file from a web server. When the task is complete should this not disappear from the above list?

Am i not ending the task correctly?

Tabletask = new CreateTablesTask();
Tabletask.execute();


class CreateTablesTask extends AsyncTask<Object, Integer, Boolean> {        

    ProgressDialog pleaseWaitDialog;

    @Override
    protected void onCancelled() {
        pleaseWaitDialog.dismiss();
    }

    @Override
    protected void onPreExecute() {
        pleaseWaitDialog = ProgressDialog.show(Activity.this, "Test", "Downloading", true, true);
        pleaseWaitDialog.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {                  
            }
        });
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }

    protected Boolean doInBackground(Object... arg0) {
        //Some code in here                 
        return null;
    }
    protected void onPostExecute(Boolean result) {          
        PleaseWaitDialog.dismiss();
        return;
    }

}
Beginner
  • 28,539
  • 63
  • 155
  • 235
  • 1
    Duplicate of [this question](http://stackoverflow.com/questions/3077461/asynctask-threads-never-die-android)? – Stephan Apr 19 '11 at 15:24

1 Answers1

1

Your code for the AsyncTask looks good.

Threads are in systems often put into pools, so that they can be reused if needed. This is sometimes faster than removing and later re-creating them.

So in general: don't worry. AsyncTask is nicely made so that you don't have to worry. I am using AsyncTasks extensively in Zwitscher and never had any issues.

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119