Skip to content

Commit

Permalink
Add 5 second delay to notification clearing to ensure notification ha…
Browse files Browse the repository at this point in the history
…s been created,

and avoid very rapid notification creation and clearing.
  • Loading branch information
rtibbles committed Nov 20, 2023
1 parent 13f75f6 commit e06afa9
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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;
Expand Down Expand Up @@ -34,8 +36,10 @@ public static void showNotification(int notificationId, String notificationTitle
}

public static void hideNotification(int notificationId) {
Context context = ContextUtil.getApplicationContext();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(notificationId);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
Context context = ContextUtil.getApplicationContext();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(notificationId);
}, 5000); // Delay in milliseconds (5 seconds)
}
}

0 comments on commit e06afa9

Please sign in to comment.