From ef5deada83c27b5f26d94e597cc188019812f2fb Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 14 Nov 2026 11:50:51 +0100 Subject: [PATCH] fix(android): write the session cookie down when the app leaves the screen The web view flushes new cookies about half a minute after a sign-in; an app Android ended in that time lost the sign-in it just had. --- .../main/java/com/liketrek/trek/MainActivity.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/client/android/app/src/main/java/com/liketrek/trek/MainActivity.java b/client/android/app/src/main/java/com/liketrek/trek/MainActivity.java index ff9238f4c..3491995d1 100644 --- a/client/android/app/src/main/java/com/liketrek/trek/MainActivity.java +++ b/client/android/app/src/main/java/com/liketrek/trek/MainActivity.java @@ -10,6 +10,7 @@ import android.view.KeyboardShortcutGroup; import android.view.Menu; import android.view.View; import android.view.ViewGroup; +import android.webkit.CookieManager; import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -90,6 +91,18 @@ public class MainActivity extends BridgeActivity { if (group != null) data.add(group); } + /** + * The web view keeps new cookies in memory and writes them to disk on its + * own schedule, about half a minute later. An app Android ends in that time + * (swiped away, or reclaimed for memory) forgets the sign-in it just had, so + * the session is written down whenever the app leaves the screen. + */ + @Override + public void onPause() { + super.onPause(); + CookieManager.getInstance().flush(); + } + @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent);