0
            public void get(View view){     
                               try {
                               asPt = new ProgressTask().execute(null,null,null);  
                               Log.d("Watcher","Get finished");         
}
            catch (Exception e) {                       
                    e.printStackTrace();                
                    Log.e("Watcher","Get Exception");       
        }       
    }

When I cancel(Boolean) the AsyncTask asPt the Line "Get finished" is never printed. Why? It also doesn't catch an Exception in this method.

Arian
  • 3,183
  • 5
  • 30
  • 58

1 Answers1

2

Remember cancel does nothing so you need to implement it yourself, see link: Android - Cancel AsyncTask Forcefully

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • 1
    cancel does something on asynctasks. it invokes onCancelled if called with Boolean false or returns null on onPostExecute if invoked with Boolean true. And even more it stops my method from beeing finished – Arian May 03 '12 at 10:17
  • @Coretek hehe true, VERY true, but it doesn't do what people expect :) – Warpzit May 03 '12 at 10:28
  • But I don't think this is intented behaviour that my method which calls this asynctask isn't finished properly when the task is cancelled ?! – Arian May 03 '12 at 10:37
  • @Coretek Okay I think I better understand your problem now. Try removing the catch block. If that doesn't work you must be crashing your app or something with the asynctask. What you are doing should work. – Warpzit May 03 '12 at 11:51
  • Ok I it out. The method doesnt wait for the AsyncTask and is executed properly. Because of that th e logcat msg came at the start instead of at the end. a AsncyTask.get() does the "join()" now – Arian May 03 '12 at 12:06