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. broadcastreceiver
s.
Comments
Post a Comment