mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-20 16:17:06 +02:00
40 lines
1002 B
Java
40 lines
1002 B
Java
package com.topjohnwu.magisk.asyncs;
|
|
|
|
import android.app.Activity;
|
|
import android.os.AsyncTask;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
|
|
|
private WeakReference<Activity> weakActivity;
|
|
|
|
private Runnable callback = null;
|
|
|
|
public ParallelTask() {}
|
|
|
|
public ParallelTask(Activity context) {
|
|
weakActivity = new WeakReference<>(context);
|
|
}
|
|
|
|
protected Activity getActivity() {
|
|
return weakActivity.get();
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public ParallelTask<Params, Progress, Result> exec(Params... params) {
|
|
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
protected void onPostExecute(Result result) {
|
|
if (callback != null) callback.run();
|
|
}
|
|
|
|
public ParallelTask<Params, Progress, Result> setCallBack(Runnable next) {
|
|
callback = next;
|
|
return this;
|
|
}
|
|
}
|