Created
January 10, 2014 07:35
-
-
Save muyiou/8348232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstarct public class SimpleBackgroundTask<T> extends AsyncTask<Void,Void,T>{ | |
| WeakReference<Activity> weakActivity | |
| public SimpleBackgroundTask(Activity activity){ | |
| weakActivity = new WeakReference<Activity>(activity); | |
| } | |
| @Override | |
| protected final T doInBackground(Void... voids) { | |
| return onRun(); | |
| } | |
| private boolean canContinue() { | |
| Activity activity = weakActivity.get(); | |
| return activity != null && activity.isFinishing() == false; | |
| } | |
| @Override | |
| protected void onPostExecute(T t) { | |
| if(canContinue()) { | |
| onSuccess(t); | |
| } | |
| } | |
| abstract protected T onRun(); | |
| abstract protected void onSuccess(T result); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment