I am using some threads in java android, I have a class which implements the runnable interface, for this i need to have a run method and this run method is called when a thread starts for example thread.start(), my problem is that i dont know how to run 2 different run methods and 2 threads. skeleton of code is below. please help on this or some explanation.Thanks a lot.
public class myTutorialsDetailsRequest implements Runnable {
//on click of button 1 start the below thread
Thread thread = new Thread(this);
thread.start();
public void run() {
//do get data 1
}
//onlick of button 2 start the below thread
Thread thread2 = new Thread(this);
thread2.start();
public void run() {
//do get data 2
}
}
Implement your own subclass of Thread for each thread you need. You may either define one class in one file or the common way (but maybe a bit harder to read for Java beginners) is to do so inline by using an anonymous class:
This defines a new subclass of Thread without giving it a name.
Do the same for the second thread.
However, consider carefully whether you really need to spawn a new thread for whatever it is you have to do.