Created
July 1, 2010 09:55
-
-
Save rorist/459787 to your computer and use it in GitHub Desktop.
How to use AsyncTask
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
import android.app.Activity; | |
import android.content.Context; | |
import android.os.AsyncTask; | |
import java.lang.ref.WeakReference; | |
private class MyTask extends AsyncTask<String, Integer, Long> { | |
private WeakReference<Activity> mActivity; | |
public MyTask(Activity activity) { | |
mActivity = new WeakReference<Activity>(activity); | |
} | |
@Override | |
protected void onPreExecute() { | |
final Activity a = mActivity.get(); | |
if (a != null) { | |
Context ctxt = a.getApplicationContext(); | |
} | |
} | |
@Override | |
protected Long doInBackground(String... strings) { | |
return 0; | |
} | |
@Override | |
protected void onProgressUpdate(Integer... progress) { | |
} | |
@Override | |
protected void onPostExecute(Long result) { | |
} | |
@Override | |
protected void onCancelled() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be: