Skip to content

Conversation

@franco-zalamena-iterable
Copy link
Contributor

@franco-zalamena-iterable franco-zalamena-iterable commented Jan 26, 2026

🔹 Jira Ticket(s) if any

✏️ Description

Migrates push notification handling from the deprecated AsyncTask to Android's WorkManager with expedited work support.


Why

AsyncTask was deprecated in API 30. Firebase and Android documentation explicitly recommend WorkManager for processing FCM messages:

"you should avoid long-running tasks (such as fetching images from a server to display in a notification) in onMessageReceived and instead schedule a task using WorkManager to handle any tasks that might take more than a couple of seconds to complete." - Firebase FCM docs

"If processing of the message payload takes longer than a few seconds, you should make sure that the processing continues in a valid process lifecycle. If you don't make sure this occurs, background execution limits may cause processing to be paused or terminated before the task completes, which can result in delayed or missing user notifications." - Firebase FCM docs

"Start an expedited job using the Android WorkManager to ensure that your high priority notification gets prioritized processing time to ensure your notification rendering runs to completion." - Firebase Blog

"In most cases, your best option for running background tasks is to use WorkManager." - Android Background Tasks


How

  • IterableFirebaseMessagingService - replaced AsyncTask execution with enqueueNotificationWork(), which schedules an expedited OneTimeWorkRequest via WorkManager. Includes a fallback that posts directly if scheduling fails.
  • IterableNotificationWorkScheduler (new) - schedules expedited work with OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST, ensuring notifications are always processed even when quota is exhausted.
  • IterableNotificationWorker (new) - Worker subclass that deserializes notification data, builds the notification, and posts it. Overrides getForegroundInfo() for pre-Android 12 compatibility.
  • IterableNotificationHelper - added null-safety checks on extras parameter.
  • IterableNotificationManager - marked @Deprecated, kept for backward compatibility.

Since minSdkVersion is 21, devices running Android 5–11 require getForegroundInfo() to avoid IllegalStateException when running expedited work:

"Failing to implement the corresponding getForegroundInfo method can lead to runtime crashes when calling setExpedited on older platform versions." - Android WorkManager docs


Dependencies

  • androidx.work:work-runtime:2.9.0
  • androidx.work:work-testing:2.9.0 (test only)


Bundle extras = IterableNotificationHelper.mapToBundle(messageData);
return IterableNotificationHelper.isGhostPush(extras);
private static void enqueueNotificationWork(@NonNull final Context context, @NonNull final Bundle extras, boolean isGhostPush) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'isGhostPush' is never used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant