I'm currently developing an app which uses GPS location on googleMaps view. I check if GPS feature is activated, and if not I redirect the user to the setting menu.
- If I click on Back button (by activating or not the GPS) I come back to my app - works fine
- If I click on Home button, and then relaunch my app, I am directly redirected to the GPS setting menu => my intent is still on.
The problem is that I do not know when kill this intent.
Here is the incriminated part of my code:
Button btnLocateMe = (Button)findViewById(Rsendlocationinfo.id.locateme);
btnLocateMe.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Context context = getApplicationContext();
objgps = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//Check GPS configuration
if ( !objgps.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
//Warn the user that its GPS is not activated
Toast gpsActivationCheck = Toast.makeText(context, "GPS deactivated - Touch to open the GPS settings.", Toast.LENGTH_LONG);
gpsActivationCheck.show();
//Open the GPS settings menu on the next onTouch event
//by implementing directly the listener method - dirt manner
mapView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
//And here is my problem - How to kill this process
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
return false;
}
});
}
else {
//Location acquisition.
}
I tried some stopself(), finish(), in onStop(), onDestroy(), onPause()... It crashes or does not do anything... Could you please give me a hand ?
use
android:launchMode="singleTask"
in AndroidManifestThe Location Settings Activity has now become part of your application/tasks when you invoked it from your calling logic. As far as Android is concerned this was the last screen from "your" application before your app became inactive. So, when you go back into the application again it will go back to that Activity automatically.
This is the normal and documented behavior. If you don't want that Activty to be there when you go back then try calling "finishActivity()" ... this only works for those Activities that were started via the startActivityForResult() method.
Ok, I have finally found.
I will try to explain the difference in the behavior clearly:
Old behavior:
The code to launch this intent was:
New behavior:
My code is now:
I tried to explain well. The tag "android:noHistory(true)" in the manifest.xml works for activities, but the flag FLAG_ACTIVITY_NO_HISTORY is a good alternative, as it works for intents.
Thank you for help.