停止不会抛出Exception Android的线程

时间:2010-12-21 07:03:36

标签: android multithreading location

所以我从手机上获得了位置修复,如果它从未找到位置或需要太长时间,问题就会出现。下面是加载屏幕的示例代码

一旦经过一段时间,我怎么能设置一个计时器来停止线程(加载屏幕)?

lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,

1000,10f,this);

Handler handler = new Handler();   Runnable showWaitDialog = new Runnable(){    int wait = 0;    @覆盖    public void run(){     while(loc == null){

}
// After receiving first GPS Fix dismiss the Progress Dialog
dialog.dismiss();

}   };

//创建一个对话框让用户知道我们正在等待GPS修复   dialog = ProgressDialog.show(Weather.this,“Please wait ...”,     “检索GPS数据......”,真实);

线程t =新线程(showWaitDialog);   t.start();

1 个答案:

答案 0 :(得分:0)

如果您想停止线程而不是使用普通线程来执行后台作业,请使用Android sdk的AsyncTask,在那里您可以找到cancel()

相关问题