Dar*_*ion 36 java android wait
我遇到了问题,我想等待10秒,因为我希望我的应用程序在10秒后启动下面的代码,但不会阻止该人点击应用程序中的任何其他内容(不调用Thread.sleep();
).
try {
Log.v("msg", "WAIT CheckFrequencyRun");
Thread.sleep(10000); // giving time to connect to wifi
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//if no network
if(wifiManager.getConnectionInfo().getNetworkId()==-1){
//stop wifi
wifiManager.setWifiEnabled(false);
Log.v("msg", "no connection");
handler.postDelayed(this, checkInterval);
}
//else connection
else{
Log.v("msg", "connection");
onDestroy();
}
Run Code Online (Sandbox Code Playgroud)
小智 155
你可以用这个:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// Actions to do after 10 seconds
}
}, 10000);
Run Code Online (Sandbox Code Playgroud)
对于停止处理程序,您可以尝试这样做:
handler.removeCallbacksAndMessages(null);
归档时间: |
|
查看次数: |
115354 次 |
最近记录: |