在我的應用程序中,在進入應用程序之前,我必須檢查我的WiFi連接並將用戶帶到WiFi設置,如果WiFi未啓用。我不想使用WifiManager.setWifiEnabled();
,因爲我想讓用戶有機會設置它。OnActivityResult過早地通過設置菜單呼叫
我剛纔提到的鏈接,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
回來後叫什麼名字?
請幫我解決這個問題.. !!