A Simple Task Library to use AsyncTask easier.Highly inspired by TinyTask,but with a simpler API.
Android's AsyncTasks are highly criticized for being bad, unreliable, outdated, etc. Are they perfect? No. Do we have better alternatives? Sure, but sometimes all we want is a quick and simple way to run something in the background.
Just a simple wrapper around an AsyncTask, with a easier API. See the case below :
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
}
@Override
protected String doInBackground(Void... params) {
return null;
}
protected void onPostExecute(String result) {
}
}.execute();
The two Void generic param is not necessary, but how can we simplify the work ? SimpleTask is the Answer.
SimpleTask.newTask(new Worker<String>() {
@Override
protected void beforeExecute() {
// execute before doInBackground. ( UI Thread )
}
@Override
protected String doInBackground() {
// do your work in background.
return null;
}
@Override
protected void afterExecute(String result) {
// execute after doInBackground. ( UI Thread )
}
}).execute();