I have a thread created inside a secondary activity on Android, like so:
new Thread(new Runnable() {
public void run() {
try {
String branch=spinner.getSelectedItem().toString();
while( branch.equals(spinner.getSelectedItem().toString())){
System.out.println("----LOOPER."+spinner.getSelectedItem().toString());
GetQinfo a= (GetQinfo) new GetQinfo().execute(city,type,org,spinner.getSelectedItem().toString());
Thread.sleep(refreshRate);
}
} catch (InterruptedException e){
e.printStackTrace();
}
return;
}
}).start();
the problem is that when i go back to the main activity this thread is still running. what i did was on the goback button to write this:
spinner.setSelection(0);
this.finish();
This way the value of the spinner is changed, causing the while loop on the thread to return false, thus exiting the thread. But i dont think this is the right way of doing it. can anyone suggest something different, or should i say, better