2

I am trying to help my users to turn on their GPS like this:

Intent gpsOptionsIntent = new Intent(  
    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);  
startActivity(gpsOptionsIntent);

The problem is that it opens the android settings as it was a view from my app, but I want to open it as a new application (android default settings aplication), in other words, outside my app.

Does anyone know how to accomplish what I want?

Thanks!

Squonk
  • 48,735
  • 19
  • 103
  • 135
lao
  • 1,670
  • 20
  • 23
  • What do you mean by "outside my app"? This code launches a new Activity outside your app, and you come back to your app when you press the back button, but this is not part of your app. – minipif Oct 02 '13 at 20:34

3 Answers3

1

The code you are executing shows a new activity "on its own app process", if the activity you are calling is not in your application project it mean's that is not in your application context, so my thought is that just because you go back and fall down in the last activity shown you may think is in your app, but that's not the case, the activity is running on it's own process and because of the back stack you are going back to your previous activity.

Hope this Helps.

Regards!

Martin Cazares
  • 13,637
  • 10
  • 47
  • 54
0

The problem is that it opens the android settings as it was a view from my app,

No it doesn't. It's starting an Activity which is part of the Android Settings app.

but I want to open it as a new application (android default settings aplication), in other words, outside my app.

That's exactly what is happening - it's just opening the Activity which deals with the settings for Location Services rather than opening the default Settings root page.

Don't confuse the generic terms 'app' and 'application' with Android classes such as Application and Activity.

Android is meant to be modular - even though it looks like the Activity which is started with your code is part of your own 'app', in reality what happens is an instance of the native Settings app is created and the Location Services Activity is displayed. This happens entirely outside of your app.

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • 1
    Ok! I understand what you are saying. But what I am looking for is a way to open the Android Settings app in a way that it would show in the recents list separately from my Aplication. Is that possible? – lao Oct 09 '13 at 12:49
  • 1
    @lucaskoala : Sorry, I don't know. If it doesn't appear in the recents list I suspect that is deliberate based on the fact that `Activity` isn't the 'root' of the Settings app. – Squonk Oct 09 '13 at 21:01
0

As mentioned in this answer and comment, you need to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Intent gpsOptionsIntent = new Intent(
    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);

// add the following line
gpsOptionsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(gpsOptionsIntent);
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74