diff --git a/python-for-android/dists/kolibri/src/main/java/org/kivy/android/PythonWorker.java b/python-for-android/dists/kolibri/src/main/java/org/kivy/android/PythonWorker.java index 72764bce..a12c70d6 100644 --- a/python-for-android/dists/kolibri/src/main/java/org/kivy/android/PythonWorker.java +++ b/python-for-android/dists/kolibri/src/main/java/org/kivy/android/PythonWorker.java @@ -35,6 +35,8 @@ public class PythonWorker extends RemoteListenableWorker { public static PythonWorker mWorker = null; + public int notificationId; + public static ThreadLocal threadNotificationId = new ThreadLocal<>(); private String notificationTitle; @@ -48,7 +50,7 @@ public PythonWorker( notificationTitle = context.getString(R.string.app_name); - threadNotificationId.set(ThreadLocalRandom.current().nextInt(1, 65537)); + notificationId = ThreadLocalRandom.current().nextInt(1, 65537); PythonWorker.mWorker = this; @@ -84,8 +86,6 @@ public ListenableFuture startRemoteWork() { runAsForeground(); } - int notificationId = getNotificationId(); - // The python thread handling the work needs to be run in a // separate thread so that future can be returned. Without // it, any cancellation can't be processed. @@ -138,7 +138,7 @@ public static native int nativeStart( ); public ForegroundInfo getForegroundInfo() { - return new ForegroundInfo(getNotificationId(), Notifications.createNotification(notificationTitle, null, -1, -1)); + return new ForegroundInfo(notificationId, Notifications.createNotification(notificationTitle, null, -1, -1)); } public void runAsForeground() { diff --git a/python-for-android/dists/kolibri/src/main/java/org/learningequality/Notifications.java b/python-for-android/dists/kolibri/src/main/java/org/learningequality/Notifications.java index bd4c38d2..78fac646 100644 --- a/python-for-android/dists/kolibri/src/main/java/org/learningequality/Notifications.java +++ b/python-for-android/dists/kolibri/src/main/java/org/learningequality/Notifications.java @@ -2,8 +2,6 @@ import android.app.Notification; import android.content.Context; -import android.os.Handler; -import android.os.Looper; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; @@ -36,10 +34,8 @@ public static void showNotification(int notificationId, String notificationTitle } public static void hideNotification(int notificationId) { - new Handler(Looper.getMainLooper()).postDelayed(() -> { - Context context = ContextUtil.getApplicationContext(); - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); - notificationManager.cancel(notificationId); - }, 5000); // Delay in milliseconds (5 seconds) + Context context = ContextUtil.getApplicationContext(); + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + notificationManager.cancel(notificationId); } }