Issue
I'd like to call my function every minute or more. my function void check if i'am connected to Wi-Fi. I was thinking about using it in while but i don't know how. If you know how to do that i'd like to know how.
My void
private void GoToNoWifi (){
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWifi.isConnected()) {
}else{
startActivity(new Intent(this,NoWifiConnection.class));
}
}
Thanks all.
Solution
Depends on when you want to know it. While loop seems to be the easiest and simplest solution.
You can use this and check every 5 seconds if there is a wifi connection or not if you don't want to do it every frame:
while (true) {
// Check for Wifi connection
// Wait 300 seconds (5 minutes) and run it again, forever
int waittime = 300;
Thread.sleep(waittime * 1000);
}
Answered By - GetMyIsland
Answer Checked By - Willingham (JavaFixing Volunteer)