Last active
August 29, 2015 14:19
-
-
Save RobGThai/cc222a41ab699e7eff3c to your computer and use it in GitHub Desktop.
Abstract class for helping with naming AsyncTask in Android.
This file contains 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
package common.asynctask; | |
import android.os.AsyncTask; | |
public abstract class NamedAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> { | |
private String oldName; | |
private void setNewThreadName(String name) { | |
oldName = Thread.currentThread().getName(); | |
if(!TextUtils.isEmpty(name)) Thread.currentThread().setName(name); | |
} | |
protected abstract String getThreadName(); | |
@Override | |
protected void onPreExecute() { | |
super.onPreExecute(); | |
setNewThreadName(getThreadName()); | |
} | |
@Override | |
protected void onCancelled() { | |
Thread.currentThread().setName(oldName); | |
super.onCancelled(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment