My problem is that I have an Activity and into there I want to take the result of the
read_list method. However the read_list method takes a lot of time to complete,
therefore I want to create a new Thread, and this to run this method and then
return it to the main activity. I know that I can do smt similar with the
AsyncTask, however now I want to do it with this way.
public class Read<T> implements Runnable(){
Thread t;
read(){
t = new Thread(this);
t.start();
}
public void run(){
read_list();
}
public ArrayList<T> read_list(){
..........
return ArrayList<T>
}
}
The main Activity:
public Name extends Activity{
.
.
.
Read<Data> read = new Read<Data>();
read.read_list();
}
Question: With the aforementioned code, will I activate a new thread to execute the
read_list method? Or the method will be executed on the main Thread?
new thread won’t be executed, however calling
read.read()should start a new threadbtw. I would prefer using anonymous class, imho it is easier to read: