lao
lao

Reputation: 1680

Can I start an activity as a new Application or outside my app?

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!

Upvotes: 2

Views: 390

Answers (3)

Afriza N. Arief
Afriza N. Arief

Reputation: 7876

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);

Upvotes: 0

Martin Cazares
Martin Cazares

Reputation: 13705

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!

Upvotes: 1

Squonk
Squonk

Reputation: 48871

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.

Upvotes: 0

Related Questions