Issue
In my Application, before going into the App, I have to check my wifi connection and take the user to the wifi settings if wifi is not enabled.
I dont want to use WifiManager.setWifiEnabled();
as I want to give the user the opportunity to set it.
I have referred the link, onActivityResult() called prematurely
and also, onActivityResult and the Settings Menu
But it is not working for me. The OnActivityResult()
and onResume()
is called almost at the same time I get into the Settings menu.
Here is my code,
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();
In the onActivityResult(), I am checking the network state again which is called before changing the settings.
What can i do so that OnActivityResult()
will be called only after coming back from the settings menu
?
Please help me with this issue..!!
Solution
This is how I solved this issue.
In reference to the answer posted for a similar question, I changed startActivityForResult() to startActivity() as the order of the action calls is like
- startActivityForResult()
- onActivityResult()
- onCreate() (new activity)
- setResult() or finish()
The control is taken to the settings page where the user can switch on/off the Wi-Fi and later come back to the app. :)
Answered By - Aswathy P Krishnan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.