Call an AsyncTask inside a Thread
<p>I am working in an android application and I want to call an AsyncTask from my UI main thread. For that I want to call my AsyncTask from a thread.</p>

<p>This is the method that I call from my main UI thread. This is working correctly</p>

<pre><code>  CommonAysnk   mobjCommonAysnk = new CommonAysnk(this, 1);
  mobjCommonAysnk.execute();
</code></pre>

<p>CommonAysnk is my AsyncTask class.I want to pass my activity and an integer parameter to the AsyncTask constructor. How can I call this from a thread as shown below method.</p>

<pre><code> Thread t = new Thread() {
                public void run() {
                    try {                       
            CommonAysnk   mobjCommonAysnk = new CommonAysnk(this, 1);
            mobjCommonAysnk.execute();
                    } catch (Exception ex) {

                    }}};                            
            t.start();
</code></pre>

<p>When I tried to call it from a Thread and I am not able to pass the activity parameter correctly. </p>

<p>This is CommonAysnk class. Please look into it</p>

<pre><code>public class CommonAysnk extends AsyncTask&lt;URL, Integer, String&gt; {

    private Common mobjCommon = null;
    private Activity mobjActivity = null;
    private int mcallIntentcond = 0;
    private ProgressDialog mProcessDialog = null;

    public CommonAysnk(Activity activity, int condition) {
        mobjActivity = activity;
        mcallIntentcond = condition;

    }
    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        mProcessDialog.dismiss();
    }
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mobjCommon = new Common();
        mProcessDialog = mobjCommon.showProgressDialog(mobjActivity, "",
                "Loading...", false);
    }
    @Override
    protected String doInBackground(URL... params) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {

        }
        switch (mcallIntentcond) {
        case 1:
            Intent i=new Intent(mobjActivity, Home.class);
            mobjActivity.startActivity(i);
            mobjActivity.finish();
            break;
        }

        return null;
    }
}
</code></pre>

<p>How can we sole this. Thanks</p>
