protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mProgressBar = (ProgressBar)findViewById(R.id.adprogress_progressBar);
final Thread timerThread = new Thread() {
private volatile boolean running = true;
public void terminate() {
running = false;
}
@Override
public void run() {
while(running) {
mbActive = true;
try {
int waited = 0;
while(mbActive && (waited < TIMER_RUNTIME)) {
sleep(200);
if(mbActive) {
waited += 200;
updateProgress(waited);
}
}
} catch(InterruptedException e) {
running=false;
}
}
}
};
timerThread.start();
}
public void onLocationChanged(Location location) {
if (location != null) {
TextView text;
text = (TextView) findViewById(R.id.t2);
String str= "Latitude is " + location.getLatitude() + "\nLongitude is " + location.getLongitude();
text.setText(str);
text.postInvalidate();
}
}
如何从 onLocationChanged 停止 onCreate 中的线程?GPS 提供坐标后,我需要停止进度条。我需要使用 join() 加入线程。解决方案会有所帮助。