diff --git a/android/app/src/main/java/app/organicmaps/MwmActivity.java b/android/app/src/main/java/app/organicmaps/MwmActivity.java index 84ff1dc614666..150f863b9085c 100644 --- a/android/app/src/main/java/app/organicmaps/MwmActivity.java +++ b/android/app/src/main/java/app/organicmaps/MwmActivity.java @@ -1116,7 +1116,7 @@ protected void onStop() Framework.nativeRemovePlacePageActivationListener(this); BookmarkManager.INSTANCE.removeLoadingListener(this); LocationHelper.from(this).removeListener(this); - if (mDisplayManager.isDeviceDisplayUsed()) + if (mDisplayManager.isDeviceDisplayUsed() && !RoutingController.get().isNavigating()) { LocationState.nativeRemoveListener(); RoutingController.get().detach(); diff --git a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java index 5f41f9f6f0c1d..b48ead0bf2705 100644 --- a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java +++ b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java @@ -44,6 +44,7 @@ public class NavigationService extends Service implements LocationListener { private static final String TAG = NavigationService.class.getSimpleName(); + private static final String STOP_NAVIGATION = "STOP_NAVIGATION"; private static final String CHANNEL_ID = "NAVIGATION"; private static final int NOTIFICATION_ID = 12345678; @@ -138,6 +139,11 @@ public static NotificationCompat.Builder getNotificationBuilder(@NonNull Context final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_CANCEL_CURRENT | FLAG_IMMUTABLE); + final Intent exitIntent = new Intent(context, NavigationService.class); + exitIntent.setAction(STOP_NAVIGATION); + final PendingIntent exitPendingIntent = PendingIntent.getService(context, 0, exitIntent, + PendingIntent.FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE); + mNotificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID) .setCategory(NotificationCompat.CATEGORY_NAVIGATION) .setPriority(NotificationManager.IMPORTANCE_LOW) @@ -147,6 +153,7 @@ public static NotificationCompat.Builder getNotificationBuilder(@NonNull Context .setOnlyAlertOnce(true) .setSmallIcon(R.drawable.ic_splash) .setContentIntent(pendingIntent) + .addAction(0, context.getString(R.string.core_exit), exitPendingIntent) .setColorized(isColorizedSupported()) .setColor(ContextCompat.getColor(context, R.color.notification)); @@ -185,6 +192,14 @@ public void onLowMemory() @Override public int onStartCommand(@NonNull Intent intent, int flags, int startId) { + final String action = intent.getAction(); + if (action != null && action.equals(STOP_NAVIGATION)) + { + RoutingController.get().cancel(); + stopSelf(); + return START_NOT_STICKY; + } + if (!MwmApplication.from(this).arePlatformAndCoreInitialized()) { // The system restarts the service if the app's process has crashed or been stopped. It would be nice to