Stopping thread that doesnt throw Exception Android
So Im getting the location fix from the phone and the problem comes up if it never finds the location or takes wayy too long. below is the sample code from the loading screen
How could i set up a timer to stop the thread(load screen) once a certain amount of time has passed?
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
1000, 10f, this);
Handler handler = new Handler(); Runnable showWaitDialog = new Runnable() { int wait = 0; @Override public void run() { 开发者_运维百科 while (loc == null) {
}
// After receiving first GPS Fix dismiss the Progress Dialog
dialog.dismiss();
} };
// Create a Dialog to let the User know that we're waiting for a GPS Fix dialog = ProgressDialog.show(Weather.this, "Please wait...", "Retrieving GPS data ...", true);
Thread t = new Thread(showWaitDialog); t.start();
If you want to stop a thread instead of using normal thread to do background jobs use Android sdk's AsyncTask
, there you can find a cancel()
.
精彩评论