点击后退按钮后应用程序出现问题(Wifi 状态)
问题描述:
我的应用程序有一个主窗口。当您单击按钮时,它会确保您已连接到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在决定是否调用第二个屏幕之前,请确保更新
network
的值。像这样的东西:Make sure to update value of
network
before making decision whether to invoke the second screen. Something like:为什么不在第二个屏幕中检查 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.