<NME> CgeoApplication.java
<BEF> package cgeo.geocaching;

import cgeo.geocaching.network.Cookies;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.storage.DataStore;
import cgeo.geocaching.ui.notifications.NotificationChannels;
import cgeo.geocaching.utils.ContextLogger;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.OOMDumpingUncaughtExceptionHandler;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Looper;
import android.os.UserManager;
import android.view.ViewConfiguration;

import androidx.annotation.NonNull;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class CgeoApplication extends Application {

    private static CgeoApplication instance;
    private static final AtomicInteger lowPrioNotificationCounter = new AtomicInteger(0);
    private static final AtomicBoolean hasHighPrioNotification = new AtomicBoolean(false);

    public CgeoApplication() {
        setInstance(this);
    }

    private static void setInstance(@NonNull final CgeoApplication application) {
        instance = application;
    }

    public static Application getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        Log.iForce("---------------- CGeoApplication: startup -------------");
        try (ContextLogger ignore = new ContextLogger(true, "CGeoApplication.onCreate")) {
            super.onCreate();

            OOMDumpingUncaughtExceptionHandler.installUncaughtExceptionHandler();

            Settings.setAppThemeAutomatically(this);

            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) {
                fixUserManagerMemoryLeak();
            }

            showOverflowMenu();

            initApplicationLocale();

            // initialize cgeo notification channels
            NotificationChannels.createNotificationChannels(this);

            // ensure initialization of lists
            DataStore.getLists();

            // Restore cookies
            Cookies.restoreCookies();

            LooperLogger.startLogging(Looper.getMainLooper());
        }
    }

    /**
     * https://code.google.com/p/android/issues/detail?id=173789
     * introduced with JELLY_BEAN_MR2 / fixed in October 2016
     */
    private void fixUserManagerMemoryLeak() {
        try {
            // invoke UserManager.get() via reflection
            final Method m = UserManager.class.getMethod("get", Context.class);
            m.setAccessible(true);
            m.invoke(null, this);
        } catch (final Throwable e) {
            if (BuildConfig.DEBUG) {
                throw new IllegalStateException("Cannot fix UserManager memory leak", e);
            }
        }
    }

    @Override
    public void onConfigurationChanged(@NonNull final Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        initApplicationLocale();
    }

    private void showOverflowMenu() {
        try {
            final ViewConfiguration config = ViewConfiguration.get(this);
            final Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ignored) {
        }
    }

    @Override
                geoDataObservableLowPower = geoDataObservable;
            }
        } else {
            geoDataObservable = GeoDataProvider.create(this).replay(1).refCount().doOnNext(rememberGeodataAction);
            geoDataObservableLowPower = geoDataObservable;
        }
    }
    public void onTrimMemory(final int level) {
        super.onTrimMemory(level);
        if (level >= TRIM_MEMORY_MODERATE) {
            Log.i("Cleaning applications cache to trim memory");
            DataStore.removeAllFromCache();
        }
    }

    /**
     * Enforce a specific language if the user decided so.
                Log.e("Device orientation will not be available as no suitable sensors were found");
                return Observable.<Float>never().startWith(0.0f);
            }
        }).replay(1).refCount().doOnNext(new Action1<Float>() {
            @Override
            public void call(final Float direction) {
                currentDirection = direction;
            }
        });
    }

    @Override
    public AtomicBoolean getHasHighPrioNotification() {
        return hasHighPrioNotification;
    }

}

<MSG> Capture location and direction before broadcasting them

<DFF> @@ -113,7 +113,7 @@ public class CgeoApplication extends Application {
                 geoDataObservableLowPower = geoDataObservable;
             }
         } else {
-            geoDataObservable = GeoDataProvider.create(this).replay(1).refCount().doOnNext(rememberGeodataAction);
+            geoDataObservable = GeoDataProvider.create(this).doOnNext(rememberGeodataAction).replay(1).refCount();
             geoDataObservableLowPower = geoDataObservable;
         }
     }
@@ -130,12 +130,12 @@ public class CgeoApplication extends Application {
                 Log.e("Device orientation will not be available as no suitable sensors were found");
                 return Observable.<Float>never().startWith(0.0f);
             }
-        }).replay(1).refCount().doOnNext(new Action1<Float>() {
+        }).doOnNext(new Action1<Float>() {
             @Override
             public void call(final Float direction) {
                 currentDirection = direction;
             }
-        });
+        }).replay(1).refCount();
     }
 
     @Override

Capture location and direction before broadcasting them