【发布时间】:2012-09-25 16:11:51
【问题描述】:
在我的应用程序中,在进入应用程序之前,我必须检查我的 wifi 连接,如果 wifi 未启用,则将用户带到 wifi 设置。
我不想使用WifiManager.setWifiEnabled();,因为我想给用户设置它的机会。
我已经引用了链接,onActivityResult() called prematurely
还有onActivityResult and the Settings Menu
但这对我不起作用。 OnActivityResult() 和 onResume() 几乎在我进入“设置”菜单的同时被调用。
这是我的代码,
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("You are not currently connected to any network. Please turn on the network connection to continue.")
alert.setPositiveButton("Settings", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int arg1)
{
Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
startActivityForResult(intent,SETTINGSCODE);
dialog.cancel();
}
});
alert.show();
在 onActivityResult() 中,我再次检查网络状态,这是在更改设置之前调用的。
我该怎么做才能OnActivityResult()
只有从settings menu回来后才会被调用?
请帮我解决这个问题..!!
【问题讨论】:
标签: android android-intent android-activity application-settings android-lifecycle