Skip to main content
15 events
when toggle format what by license comment
Feb 1, 2017 at 2:52 history edited cpx CC BY-SA 3.0
added 1 character in body
Oct 23, 2016 at 20:26 comment added Vigen So if I'll implement AsyncTask as a normal class(not inner class) and keep my references valid(it possible with listener/observer pattern) then can I use AsyncTask for long running processes?
Jan 12, 2016 at 21:59 comment added Snicolas Cancelling cancel would probably prevent the leak, though cancelling a task highly depends in its state. For instance if the thread is in IO blocking state, there is no way to cancel it before it returns... And more than all, calling cancel means that you loose the data you already acquired + the time you spent to establish the connection... RS provides a better solution.
Dec 2, 2015 at 11:00 comment added user1263800 @Snicolas question, what if we call .cancel(boolean) on the long running async task from onPause() (before orientation happens), will it stop immediately and prevent the leak? question2, if we create a new thread, do we need to keep an eye on it, when activity get's on background / destroyed - do we need to cancel it too;
Sep 4, 2014 at 14:57 comment added eddy @Snicolas Not even using a broadcast receiver or LocalBroadcastManager?
Sep 4, 2014 at 13:05 comment added Snicolas @eddy, you would still have to deal with the service life cycle. Moreover, it would not be easy to setup a callback.. Anyhow, it would be a bit like using a degraded version of RS, and it has much more than this to offer..
Sep 4, 2014 at 12:03 comment added eddy Is it the same even if I start the AsyncTask inside a Service?? I mean, would the long running operation still be a problem?
Jul 19, 2013 at 11:11 comment added turtleboy @Snicolas mmm i'm not really that keen to bring in libraries to the app, i'd rather use a fix for AsyncTask, IntentService maybe an option or some pure Java threading alternative to Async. I'm not disregarding RoboSpice but i need to sort this in next few days as my company's client is backing out! 10's of thousands of £ :( Am i right in saying there is no way to forcibly cancel an AsyncTask with just Cancel(true)?
Jul 19, 2013 at 9:31 comment added Snicolas You should have a try at RoboSpice (on github). ;)
Jul 19, 2013 at 9:12 comment added turtleboy here's the link stackoverflow.com/questions/17725767/…
Jul 19, 2013 at 9:12 comment added turtleboy @Snicolas Thanks for the reply. I made a post on SO yesterday outlining my problem and showing the handler code i've written to try stop the AsyncTask after 8 seconds. Would you mind having a look at, if you get time? Will calling AsyncTask.cancel(true) from a Handler cancel the task properly? I know i should check periodically the value of iscancelled() in my doInBackgroud, but i don't think applies to my circumstances as i'm just making a one line webcall HttpPost and not publishing updates on the UI.Are there alteratives to AsyncTask eg is it possible to make a HttPost from an IntentService
Jul 19, 2013 at 5:56 comment added Snicolas Trace to see what happens. But yes, that's quite possible ! If you desin well your asynctask, you can cancel it rather properly, that would be a good starting point if you don't want to migrate to RS or a service...
Jul 18, 2013 at 21:26 comment added turtleboy @Snicolas Hi. I have an app where it scans data from an NFC tag and sends to server. It works fine in good signal areas but where no signal the AsyncTask that makes the webcall keeps running. eg the progress dialog box runs for minutes and then when it does disappear the screen turns black and unresponsive. My AsyncTask is an inner class. I'm writing a Handler to cancel the task after X secs. The app seems to send old data to the server hours after the scan. Could this be due to AsyncTask not finishing and then maybe completing hours after? I would appreciate any insight. thanks
Oct 26, 2012 at 18:36 vote accept user1730789
Oct 26, 2012 at 6:45 history answered Snicolas CC BY-SA 3.0