Android 使用“设置”菜单过早调用OnActivityResult
在我的应用程序中,在进入应用程序之前,我必须检查我的wifi连接,如果未启用wifi,则将用户带到wifi设置 我不想使用Android 使用“设置”菜单过早调用OnActivityResult,android,android-intent,android-activity,application-settings,android-lifecycle,Android,Android Intent,Android Activity,Application Settings,Android Lifecycle,在我的应用程序中,在进入应用程序之前,我必须检查我的wifi连接,如果未启用wifi,则将用户带到wifi设置 我不想使用WifiManager.setWifiEnabled()因为我想让用户有机会设置它 我已经提到了链接 而且 但这对我不起作用。几乎在我进入设置菜单的同时,调用了OnActivityResult()和onResume() 这是我的密码 AlertDialog.Builder alert = new AlertDialog.Builder(this); aler
WifiManager.setWifiEnabled()代码>因为我想让用户有机会设置它
我已经提到了链接
而且
但这对我不起作用。几乎在我进入设置菜单的同时,调用了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()上的
只有从设置菜单返回后才会调用
请帮我解决这个问题 我就是这样解决这个问题的
参考一个类似问题的帖子,我将startActivityForResult()更改为startActivity(),因为动作调用的顺序如下
startActivityForResult()
onActivityResult()
onCreate()(新活动)
setResult()或finish()
该控件将转到设置页面,用户可以在该页面打开/关闭Wi-Fi,然后返回应用程序:)