Wait for the task to complete.

I need to wait until the android turns on Wi-Fi (you can’t just “setWifiEnabled (true)” and wait for activation right away). I need the right way to do this.

I have the code and its work, but I don’t think its the right way to get the job done (I think)

while(wifiManager.getWifiState() != 3) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

I already checked to wait until Wi-Fi connects to android , but I did not find the answer I need.

+4
source share
1 answer

The correct way is to register for Wi-Fi connection events. Then Android will call you when it connects. See How to determine when a WIFI connection is established in Android?

+3
source

All Articles