java - Android multithreading and services -
hi little bit confused multithreading in android, aware can accomplish using asynctask , handlers , when should implement extending thread class in android , can give illustration need extending thread class not asynctask or handler.
1)suppose consider illustration app, have bouncing ball in activity(forget animation part), need alter color of ball every 20 minutes, , need color code server , update ball ui, how can accomplish , can explain using asynctask or handler , using thread class(without asynctask or handler)
2) how should handle downloading big payloads server using services.
thread
- long task in general - invoke thread.start() method - triggered thread - runs on own thread - manual thread management/code may become hard read asynctask
- little task having communicate main thread - invoke excute() method - triggered main thread - runs on worker thread - must executed , created main thread service
- task no ui,but should not utilize long task. utilize thread within service long task - invoke onstartservice() - triggered thread - runs on main thread - may block main(ui) thread intentservice
- long task no communication main thread if communication needed done handler or broadcast - invoke via intent - triggered main thread (intent received on main thread , worker thread spawed) - runs on separate thread - can't run task in parallel , multiple intents queued on same worker thread. java android multithreading service android-asynctask
No comments:
Post a Comment