質問

I override onReceivedError to create a dialog to let the user turn on the wifi if it is off.

My code there is something like:

if (! mWifi.isConnected() ) {

  Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS);
  startActivity(i);
}

This open the wifi settings, and after the user turn on wifi and hit back.... What i need to add to restart the main activity?

役に立ちましたか?

解決

Launch Settings.ACTION_WIFI_SETTINGS using startActivityForResult instead of startActivity because when user return back then onActivityResult method called in Activity where you can check again is wifi is enabled or not before restarting Activity.

Start WIFI setting as:

startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS),0);

Override onActivityResult method in Activity as:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    if(requestCode==0)
    {
           WifiManager wifiManager = (WifiManager) 
                                     getSystemService(Context.WIFI_SERVICE);
        if(!wifiManager.isWifiEnabled())
           //restart Application here
    }    
}

他のヒント

You have o do that:

we considered: current Activity = ActivityCurrent and : your main Activity = MainActivity

in your MainActivity do : MainActivity extends ActivityCurrent

and in your CurrentActivity restard your MainActivity like that:

                      Intent intent1 = getIntent();
                      finish();
                      startActivity(intent1);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top