Android: Executing method from specific thread
<p>I'm developing an application in Android. The application can post a HTTP request to specific web server. That post request must run asyncronously, so I create a thread to do the job. But I need a callback that will be called at thread end and it must be called from thread that call the `post` method.</p>

<p>My <code>post</code> method looks like this:</p>

<pre><code>interface EndCallback
{
    public void Success(String response);
    public void Fail(Exception e);
}

public void post(final String url, final List&lt;NameValuePair&gt; data, EndCallback callback)
{
    Thread t = Thread.currentThread();
    (new Thread()
    {
        public void run()
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);
            try
            {
                httppost.setEntity(new UrlEncodedFormEntity(data));
                HttpResponse r = httpclient.execute(httppost);

                HttpEntity en = r.getEntity();
                String response = EntityUtils.toString(en);

                //I want to call callback.Success(response)
                //here from thread t
            } 
            catch (Exception ex)
            {
                //And I want to call callback.Fail(ex)
                //here from thread t
            }
        }
    }).start();
}
</code></pre>
