我遇到了一个问题,我想要等待十秒钟,因为我希望我的应用程序在这十秒钟后开始下面的代码,但是又不想停止用户进行应用程序中其他操作(不使用 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();
}