简体   繁体   中英

Wait until task is completed

I need to wait until android enables wifi ( you can't just "setWifiEnabled(true)" and expect to be enabled instantly). I need proper way to do that.

I have some code and its working, but i don't think its proper way to get 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 wait until wifi connected on android , but i didn't found answer i need.

The right way is to register for wifi connection events. Then Android will call you when its connected. See How to detect when WIFI Connection has been established in Android?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM