Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to use AsyncTask
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