Allowing AsyncTask to Manipulate Values in Different Activity Classes

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2011-02-12T07:22:46Z Indexed on 2011/02/12 7:25 UTC
Read the original article Hit count: 212

Filed under:
|
|

Hi guys,

This title may seem strange, so let me try to explain what I'm trying to do. I have several activity classes, each representing a different view in my application. My initial activity class gets loaded when the application launches. The user enters values and eventually a TCP socket is opened, and I then use AsyncTask to listen for and respond to messages from the server. I'd like for this AsyncTask class to essentially listen until the app is closed/error condition reached, and be able to update values in other activity classes after they are started. Does this make sense (it's been a long, frustrating night)? I know that static activity class references are bad practice, and touching the UI thread from other activities is bad as well, but I'm having trouble finding a clean solution to this problem. Maybe using AsyncTask is not the best approach here? Should I be using a service instead or something else entirely?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about android

Related posts about activity