我遇到了一个问题,我想等待 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();
}