AsyncTask
is not obsolete (nor is it deprecated), but it's probably not a good choice for persistent socket communication. AsyncTask
is better suited to relatively short-lived operations, including ones that make UI modifications to show progress or upon completion since the threading is handled for you. Because you can use AsyncTask
to modify the UI, most people associate the AsyncTask
with their Activity
or some of its View
s, which can be a problem since any configuration change may cause the Activity
to be destroyed and recreated, but you will still have an AsyncTask
living in memory holding on to the entire Activity
context.
For something like a persistent socket, you are better off using a Service
, which is a separate application component that won't go through configuration changes like Activity
s do. You can also manage its lifecycle differently, whereas the Activity
lifecycle is dictated primarily by user interaction.