Threading in Android

Posted by virsir on Stack Overflow See other posts from Stack Overflow or by virsir
Published on 2010-06-13T06:11:54Z Indexed on 2010/06/13 6:22 UTC
Read the original article Hit count: 190

Filed under:
|
|

I am currently developing Android app, it needs download content from internet. I use thread to do that and then call runOnUiThread method to update GUI.

  1. I placed a refresh menu on it, if user tried to refresh the content, the download thread will be created and started. The problem is that how can I control the thread order, I need to accept the latest request's response and abandon previous thread requests if there were some other requests still running because the request parameters may have been changed by user. Currently I was using a threadId to do this thing, when a thread finished, it will check its threadId, if it was the latest recored one, it then takes control and render the response. My question is that is there any other proper better solution for this?
  2. Do I need to stop threads when user exit the app? I remember that some book said that do not try stop thread manually and wait itself finish is a good practice, is that true? Should I stop them by calling "stop" or "interrupt" method?
  3. I read some documents around threading in Android and found the class HandlerThread, what is it? In what kind of situation I need to use it?

© Stack Overflow or respective owner

Related posts about java

Related posts about android