Fix: NotificationOpenedActivity "freeze" when a large amount of notification is clicked #2304
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Move the backend call
updateNotificationsAsOpened
to a background thread to prevent blocking the next activity from opening when many notifications are clicked.Details
Motivation
Fix a frozen screen issue that occurs when a large number of notifications are clicked simultaneously.
Scope
updateNotificationsAsOpened
operation is now performed silently in the background. This means we no longer wait for its response before opening the destination activity upon a notification click. As a result, the order of this operation relative to other operations is no longer guaranteed. A potential risk is that IDs may change beforeupdateNotificationsAsOpened
completes on the backend. However, since all data is finalized at the time the requests are created, data integrity is maintained without blocking the UI.createUser
andupdateSubscription
. As a result, these operations could potentially be delayed if too manyupdateNotificationsAsOpened
calls are made.One possible improvement would be to introduce a
SecondaryCoroutineScope
to handle lower-priority updates, but since they’re all backend calls, the overall time required to complete them remains roughly the same.updateNotificationsAsOpened
calls may be interrupted, and those clicks might not be updated on the backend.Testing
Unit testing
A new unit test ensures that
openDestinationActivity
is not blocked when clicking on a large number of notifications.Manual testing
Tested on a Pixel 9 (API 35) emulator. Clicking a summary notification that groups 50+ individual notifications opens the app seamlessly. The
updateNotificationsAsOpened
calls are successfully processed in the background after the app is opened.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is