I hate inner class.
I\'ve a main activity who launches a \'short-life\' AsyncTask.
AsyncTask is in a separate file, is not an inner class of
I wrote a small extension to AsyncTask for this kind of scenario. It allows you to keep your AsyncTask in a separate class, but also gives you convenient access to the Tasks's completion:
public abstract class ListenableAsyncTask extends AsyncTask{
@Override
protected final void onPostExecute(Result result) {
notifyListenerOnPostExecute(result);
}
private AsyncTaskListener mListener;
public interface AsyncTaskListener{
public void onPostExecute(Result result);
}
public void listenWith(AsyncTaskListener l){
mListener = l;
}
private void notifyListenerOnPostExecute(Result result){
if(mListener != null)
mListener.onPostExecute(result);
}
}
So first you extend ListenableAsyncTask instead of AsyncTask. Then in your UI code, make a concrete instance and set listenWith(...).