Access outer variables inside dispatchMessage
<p>I'm dealing with legacy code. My task is to process the result of an async task.</p>

<p>I'm stuck with getting access to outer objects inside dispatchMessage method. Are there any means achieve it or should I use Singleton or static properties ? </p>

<p>So far I've made a class responsible for running in asynchronous mode.</p>

<pre><code>private class BackgroundTask extends AsyncTask&lt;Object, Void, Boolean&gt; 
    { 
        @Override
        protected Boolean doInBackground(Object... params){
            // ...
        }

        @Override
        protected void onPostExecute(Boolean result){
            // ...
        }


    }
</code></pre>

<p>Inside the OnPostExecute or the doInBackground method I'd like to send a message using a handler, so I push in some simple stuff:</p>

<pre><code>Message m = new Message();
Bundle b = new Bundle();
b.putString("sizeKEY", "size " + _count);
m.setData(b);
_handler.sendMessage(m);
</code></pre>

<p>And I need to access outer objects right here:</p>

<pre><code>new Handler(){
@Override
    public void dispatchMessage(Message msg) {
                super.dispatchMessage(msg);
                // get access to, say, Activity property or method here 
            }
        }
</code></pre>

<p>How is it done ?</p>
