cherry-wave cherry-wave - 28 days ago 15
Android Question

Android: Alternatives to AsyncTask?

for my app I made a framework for all network calls to an external API. I put everything in "Services" like:

UserService
,
MessageService
etc. So now when I want to call a network method I can't do this in the UI-Thread of my
Activity
so I made an
AsyncTask
and everything was just fine =)

But now I want something like giving the method to execute to the
AsyncTask
so I don't need to write an
AsyncTask
for every method of my network-framework. So instead of having something like this:

public class NetworkTask extends AsyncTask<UserService, Void, Void> {

@Override
protected Void doInBackground(UserService... params) {
UserService userService = params[0];
userService.getUser();
return null;
}
}


I want something more "abstract" so the
AsyncTask
doesn't need to know the "getUser" method? But I can't find any idea of how to do this... Maybe the AsyncTask is not good for this anyway?

Answer

There are plenty AsyncTask alternatives :

https://android-arsenal.com/tag/9

and plus Needle - Multithreading library for Android

http://zsoltsafrany.github.io/needle/

Comments