Udi Oshi Udi Oshi - 1 year ago 93
Android Question

onActivityResult for Intent(Settings.ACTION_SETTINGS) called immediately

In my splash screen I have request to server, but when there's no internet connection i'm opening

Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
startActivityForResult(settingsIntent, REQUEST_ENABLE_CONNECTION);

But problem is that
is called immediately with requestCode =

I've also tried to add the flag
for the intent with no luck.

The activity is not
in the

What is the best android solution to resolve this issue? I don't want to use Broadcast as it's not the best way to my flow so it will be taken as last choice for me.

Thanks a lot for the help.

Answer Source

If the onActivityForResult isn't working well for you (as @CommonsWare suggested, it's fine) you can create a simple flow that should work fine:

In your activity, add

private boolean isReturnedFromSettings = false;

When you decide there's no internet connection and want to open the settings activity, use startActivity and set isReturnedFromSettings = true;

In your Activity's onResume, add this:

if (isReturnedFromSettings) {
isReturnedFromSettings = false;


Should work...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download