开发者

Problem in app after hitting the back button (Wifi state)

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开发者_StackOverflow();                      
                }  
            });  

         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 network before making decision whether to invoke the second screen. Something like:

askForWiFi();
if(network){
   invoke...
}else{
   go to settings
}


Why don't you check for WiFi in the second screen instead? If it's not there, ask them to enable it there or send them back to the home screen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜