From cefca1481ad15d29249dbf0a5ba565f399955cad Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Fri, 2 Feb 2024 13:05:28 +0300 Subject: [PATCH] Fix waypoint remove before exit --- app/src/main/java/mobi/maptrek/MapTrek.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/mobi/maptrek/MapTrek.java b/app/src/main/java/mobi/maptrek/MapTrek.java index 0556dde5..7be93859 100644 --- a/app/src/main/java/mobi/maptrek/MapTrek.java +++ b/app/src/main/java/mobi/maptrek/MapTrek.java @@ -515,7 +515,8 @@ synchronized public void optionallyCloseMapDatabase(UUID id) { } } - public void onMainActivityFinishing() { + public void onMainActivityFinished() { + logger.info("MainActivity finished"); optionallyCloseMapDatabase(null); if (mWaypointDbDataSource != null) { mWaypointDbDataSource.close(); @@ -630,7 +631,6 @@ public void uncaughtException(@NonNull final Thread thread, @NonNull final Throw } class ListeningToActivityCallbacks implements Application.ActivityLifecycleCallbacks { - @Override public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) { logger.warn("{} is onActivityCreated", activity.getLocalClassName()); @@ -666,10 +666,14 @@ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bun @Override public void onActivityDestroyed(@NonNull Activity activity) { logger.warn("{} is onActivityDestroyed", activity.getLocalClassName()); - if (activity.isFinishing() && activity.getLocalClassName().equals(MainActivity.class.getSimpleName())) { + if (activity.isFinishing() && activity.getLocalClassName().equals(MainActivity.class.getSimpleName())) mMainActivityExists = false; - onMainActivityFinishing(); - } + } + + @Override + public void onActivityPostDestroyed(@NonNull Activity activity) { + if (!mMainActivityExists && activity.getLocalClassName().equals(MainActivity.class.getSimpleName())) + onMainActivityFinished(); } } }