Skip to content

Instantly share code, notes, and snippets.

@RobGThai
Last active August 29, 2015 14:19
Show Gist options
  • Save RobGThai/cc222a41ab699e7eff3c to your computer and use it in GitHub Desktop.
Save RobGThai/cc222a41ab699e7eff3c to your computer and use it in GitHub Desktop.

Revisions

  1. RobGThai revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NamedAsyncTask.java
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ public abstract class NamedAsyncTask<Params, Progress, Result> extends AsyncTask

    private void setNewThreadName(String name) {
    oldName = Thread.currentThread().getName();
    Thread.currentThread().setName(name);
    if(!TextUtils.isEmpty(name)) Thread.currentThread().setName(name);
    }

    protected abstract String getThreadName();
  2. RobGThai renamed this gist Apr 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. RobGThai created this gist Apr 16, 2015.
    26 changes: 26 additions & 0 deletions NamedAsyncTask
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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();
    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();
    }
    }