Call an AsyncTask inside a Thread
- by Arun
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