You should use a background thread and delegate its access via a service.

Basically when you want to start a download, you send an intent with
the necessary parameters.  In the service handler you put this data in
some persistent location (such as a content provider), ask the thread
to do the download. The thread will eventually respond, if you need to
do many at a time you can use a thread pool.  Serializing the state
inside a content provider is necessary to prevent the situation where
you app just dies.  You also want to check the download isn't already
in progress (the UI should properly handle the case where it is), this
is also accomplished with a database.

Kris


On Tue, Feb 26, 2013 at 10:34 AM, bob <[email protected]> wrote:
> So, I have an app.
>
> When you press a button, it makes a TCP connection to a server and tells it
> to play a movie.
>
> It may have 10 buttons and 10 movies.
>
> Obviously, the TCP connection should not be done on the UI thread.
>
> But how should it be done?
>
> One difficulty is that there will only be one TCP connection thru the
> lifetime of the app - it will not reconnect.
>
> I would think AsyncTask maybe…  But the problem there is what happens if the
> user monkeys with the buttons and just starts pressing buttons really fast.
> Should I maybe store up AsyncTasks on a queue so that there is not the
> potential for really weird behavior in the face of monkeying?
>
> I'm not sure how to put AsyncTasks on a queue.
>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to