How to check a method as long as the app is open
<p>For example, I want to check if wifi is enabled forever . If it is enabled my button will turn on, if it is off my button will turn off, but when I use my method(I will provide it) it only checks once when the app is created, but I want it to check as long as possible until the phone is turned off or the process it killed, if someone could help that would be great!</p>

<p>Wifi Check Method:</p>

<pre><code>  public void checkWifi() {

    WifiManager wifim = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    ToggleButton wifi=(ToggleButton)findViewById(R.id.wifibutton);

    if (wifim.getWifiState()==(WifiManager.WIFI_STATE_ENABLED)) {

        wifi.setChecked(true);

    } else {

...

}
</code></pre>
