Reputation: 372
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?
Upvotes: 0
Views: 1932
Reputation: 134
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);
Upvotes: 0
Reputation: 132982
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
}
}
Upvotes: 2