I have an event in the main thread that creates another thread. This new thread must sleep for 60 seconds and then it must check the main thread state. My code is this:
public class Act extends Activity {
Object lock=new Object();
public class MainT implements LocationListener {
public String str="";
public void onLocationChanged(Location location) {
synchronized(lock) {
str=String.valueOf(location.getLatitude())+" "+String.valueOf(location.getLongitude());
new SecondT(str).start();
}
}
class SecondT extends Thread {
public String st;
SecondT(String s) {
st=s;
}
public void run() {
waitSeconds();
}
public void waitSeconds() {
try {
Thread.sleep(60000);
synchronized(lock) {
if (str.equals(st))
Log.d("SecondT", "Same string.");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
MainT mt = new MainT();
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 50, mt);
}
}
The problem is that if a start that thread, it's the MainT that sleeps (the GPS event isn't called even if i pass new coordinates through the debug tool).