multithreading - Chaining together AsyncTasks in Android - better to use Threads? -
i have series of network operations must done sequentially:
- connect specific wifi device's ap
- send data on tcp
- connect different ap
- send udp broadcast
i have implemented starting each asynchtask
in onpostexecute
of previous asynchtask
. realize in different part of app reuse code asynchtask 2
(to send different data), can't because not want asynchtask 3
start when finished. realize use flag (a boolean or int) , pass asynchtask 2
, not start asynchtask 3
if flag false, seems confusing , messy.
can done in cleaner way using threads? or end using same logic i.e. using flag in run()
method?
let me know if me post code, long , feel question pretty clear.
if know you're going running of these tasks in sequence, why not put them in same asynctask
? can still use different classes or functions make code more compartmentalized.
Comments
Post a Comment