How to pass the AppDelegate reference from activity to async task?
<p>I'm trying to reduce the noise in my activity classes (Android) and the first thing I've pulled out is the async tasks I had as inner classes. The only issue I'm having is that I'm not able to pass the AppDelegate ref from the activity to the async task once it's moved out.</p>

<p>Here is my (failed) attempt at it</p>

<p>//here I pass the ref from the activity</p>

<pre><code>public class HelloAndroidActivity extends Activity {
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        GetSessionsAsyncTask task = new GetSessionsAsyncTask(HelloAndroidActivity.this, getApplicationContext());
        task.execute();
    }
}
</code></pre>

<p>//here I push it to a field to use it later (but it fails during the init of this obj)</p>

<pre><code>public class GetSessionsAsyncTask extends AsyncTask&lt;String, Void, List&lt;Session&gt;&gt; {
    private Activity activity;
    private AppDelegate delegate;

    public GetSessionsAsyncTask(Activity activity, Context context) {
        this.activity = activity;
        this.delegate = (AppDelegate) context;
    }
}
</code></pre>

<p><strong>Edit</strong></p>

<p>the app delegate I mention above just extends application (android class)</p>

<pre><code>public class AppDelegate extends Application {
}
</code></pre>
