点击后退按钮后应用程序出现问题(Wifi 状态)

发布于 2024-11-19 05:37:20 字数 1907 浏览 4 评论 0原文

问题描述:

我的应用程序有一个主窗口。当您单击按钮时,它会确保您已连接到 wifi 或 3g,如果没有连接,则会弹出一个启用 wifi 的对话框。 当 wifi 打开并单击按钮时,会显示一个新屏幕。当您点击后退按钮,禁用 wifi 并再次单击该按钮时,它不会再次请求 wifi 并且屏幕显示没有 wifi....

在我有的按钮的 Click 事件中:

 if(chosedOption == curOption)
            {
                if(network)
                {
                    target = CurrencyMain.class;
                    go.setAnimation(a);
                }
                else
                    askForWifi();
            }

在 askForWifi 方法中我有:

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;

 }

我能做什么来解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煞人兵器 2024-11-26 05:37:20

在决定是否调用第二个屏幕之前,请确保更新network的值。像这样的东西:

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

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
}
荆棘i 2024-11-26 05:37:20

为什么不在第二个屏幕中检查 WiFi 呢?如果不存在,请要求他们在那里启用它将他们发送回主屏幕。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文