A SimpleRxTask, base on RxJava2, take plase of AsyncTask of Android.
Improvements:
-
Safe. Catch exceptions internal Compare with AsyncTask.
-
Rubust. Cancel() in main/worker thread while AsyncTask sometimes has bugs with cancel().
-
Consistent. Don't need to care about different implement of AsyncTask in Android 2.3 ~ 8.0
-
Simple. like : SimpleRxTask<PROGRESS, RESULT> , instead of AsyncTask<Params,Progress,Result>, because you can pass Params in when onPrepare()
Usage:
dependencies {
compile 'com.github.oyyj42:SimpleRxTaskDemo:v1.0.1'
}
demo:
mTask = new SimpleRxTask<Integer, String>() {
@Override
protected void onPrepare() {
}
@Override
protected String doInBackground() throws Exception {
return "hello";
}
@Override
protected void onProgress(Integer integer) {
5505
}
@Override
protected void onSuccess(String result) {
Log.i(TAG, "result:" + result);
}
@Override
protected void onCancelled() {
}
};
mTask.start();