Call an AsyncTask inside a Thread

Posted by Arun on Stack Overflow See other posts from Stack Overflow or by Arun
Published on 2012-10-03T09:29:14Z Indexed on 2012/10/03 9:37 UTC
Read the original article Hit count: 154

Filed under:

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.

This is the method that I call from my main UI thread. This is working correctly

  CommonAysnk   mobjCommonAysnk = new CommonAysnk(this, 1);
  mobjCommonAysnk.execute();

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.

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

                    }}};                            
            t.start();

When I tried to call it from a Thread and I am not able to pass the activity parameter correctly. How can we sole this. Thanks

© Stack Overflow or respective owner

Related posts about android