How to stop code execution while waiting for Wifi and Bluetooth adapters to enable in Android? -


i had manually turn on network adapters in program, , on android takes while hardware power up, second.

//turn on network adapters wifimanager.setwifienabled(true); bluetoothadapter.enable();  while(wifimanager.getwifistate()!=wifimanager.wifi_state_enabled | bluetoothadapter.getstate!=bluetoothadapter.state_on)     ; //no code here, waiting adapters enable  //continue execution getdeviceinfo(); 

the above method i'm using not elegant @ all, cpu locked-up in while loop. ideas how implement in better way?

at least, can put in thread (check out asynctask) , have thread.sleep(10) in while loop.

going deeper, can register broadcast events notified when wifi state changes. way, can react if outside app changes wifi state. broadcastreceivers.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -