Problem Description:
my app has a main window. when you click a button it make sure you are connected to wifi or 3g, if not it pop up a dialog that enables wifi.
when wifi is on and the button is clicked a new screen shows up. when you hit the back button, disable wifi and click that button again it does not ask for wifi again and the screen shows up without wifi….
In the Click event of the button i have:
if(chosedOption == curOption)
{
if(network)
{
target = CurrencyMain.class;
go.setAnimation(a);
}
else
askForWifi();
}
and in the askForWifi method i have:
public void askForWifi()
{
is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
network = is3g||isWifi;
if(!network)
{
AlertDialog alertbox = new AlertDialog.Builder(MainWindowYuval.this).create();
alertbox.setMessage("Enable wifi of 3g!");
alertbox.setButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertbox.setButton2("Turn wifi on", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
WifiManager wifiManager = (WifiManager) MainWindowYuval.this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
}
});
alertbox.show();
}
is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
network = is3g||isWifi;
}
what can i do to fix this?
Make sure to update value of
networkbefore making decision whether to invoke the second screen. Something like: