From 4ac39606dff1f7f74c739ceb2b48d990de6c3a98 Mon Sep 17 00:00:00 2001 From: iusmac Date: Wed, 14 Jan 2026 09:38:37 +0100 Subject: [PATCH] chore(ui): drain Handler thread queue when activity is destroyed Currently, we don't have any tasks that could execute after the Activity is destroyed and lead to crashes or unexpected behaviors. So, it's better to drain this static Handler thread's queue upon Activity destruction to prevent quite realistic, well-known bugs tied to Android lifecycle that we might face in the future if making any changes. --- .../iusmac/sevensim/ui/scheduler/SchedulerActivity.java | 7 +++++++ src/com/github/iusmac/sevensim/ui/sim/SimListActivity.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/com/github/iusmac/sevensim/ui/scheduler/SchedulerActivity.java b/src/com/github/iusmac/sevensim/ui/scheduler/SchedulerActivity.java index d3dfd49a..64c932a4 100644 --- a/src/com/github/iusmac/sevensim/ui/scheduler/SchedulerActivity.java +++ b/src/com/github/iusmac/sevensim/ui/scheduler/SchedulerActivity.java @@ -160,4 +160,11 @@ protected void onPause() { mSubscriptions.removeOnSubscriptionsChangedListener(this); sHandler.removeCallbacksAndMessages(mSubscriptionsChangedToken); } + + @Override + protected void onDestroy() { + super.onDestroy(); + + sHandler.removeCallbacksAndMessages(null); + } } diff --git a/src/com/github/iusmac/sevensim/ui/sim/SimListActivity.java b/src/com/github/iusmac/sevensim/ui/sim/SimListActivity.java index eead4a9b..4cdcbc29 100644 --- a/src/com/github/iusmac/sevensim/ui/sim/SimListActivity.java +++ b/src/com/github/iusmac/sevensim/ui/sim/SimListActivity.java @@ -145,6 +145,13 @@ protected void onPause() { unregisterReceiver(mIntentReceiver); } + @Override + protected void onDestroy() { + super.onDestroy(); + + sHandler.removeCallbacksAndMessages(null); + } + @VisibleForTesting final class IntentReceiver extends BroadcastReceiver { @Override