fix(notify): open MainActivity when notification is tapped - #225
fix(notify): open MainActivity when notification is tapped#225TimeToBuildBob wants to merge 2 commits into
Conversation
Without a setContentIntent, tapping an activity-time alert notification did nothing. Add a PendingIntent that brings MainActivity to the front (or starts it), opening the AW dashboard/activity view. BackgroundService already had this pattern for the foreground-service notification; NotifyWorker's category-alert notifications were missing it. Fixes: ActivityWatch#224
Greptile SummaryThe PR makes activity-time alert notifications open MainActivity when tapped.
Confidence Score: 4/5The PendingIntent collision should be fixed before merging because alert taps can still create a duplicate MainActivity instead of bringing the current instance forward. NotifyWorker requests the same MainActivity PendingIntent identity already owned by BackgroundService, so the newly specified CLEAR_TOP and NEW_TASK behavior is not reliably represented by the returned token. Files Needing Attention: mobile/src/main/java/net/activitywatch/android/workers/NotifyWorker.kt Important Files Changed
Reviews (1): Last reviewed commit: "fix(notify): open MainActivity when noti..." | Re-trigger Greptile |
|
CI-green and mergeable — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
BackgroundService's foreground notification already registers request code 0 for a MainActivity PendingIntent with no launch flags. PendingIntent identity is (requestCode, Intent.filterEquals) — extras and launch flags are not part of it, and FLAG_UPDATE_CURRENT replaces only extras. Reusing code 0 therefore resolved to that existing PendingIntent and silently dropped FLAG_ACTIVITY_CLEAR_TOP, so tapping an alert could stack a second MainActivity instead of bringing the existing one forward. Use request code 1 (0 and 2 are taken by BackgroundService and the widget) and name the collision in a comment so it does not regress.
|
Correction to my 02:48 comment: this was not "waiting only on a maintainer click" — an unaddressed Greptile P1 had been sitting on it for 4 days. My earlier comment read the green CI and mergeable state and skipped the open review thread. Apologies for the noise. The finding was real. Fixed in 64c933d: request code Re-running CI now — will confirm green before this is actually ready. |
|
CI green on 64c933d — confirming as promised:
Greptile thread resolved. No open review threads remain. Now genuinely ready for a maintainer merge — the bot is pull-only here. |
Problem
Tapping an activity-time alert notification ("Time spent: Work 1h 30m") did nothing. The
NotifyWorker.sendNotification()method built notifications without asetContentIntent, which is the Android API for wiring up a tap action.Fix
Add a
PendingIntentthat opensMainActivity— the AW dashboard/activity view — when the notification is tapped. UsesFLAG_ACTIVITY_CLEAR_TOPso an already-running instance is brought to the front rather than starting a new one.BackgroundServicealready had this pattern for the foreground-service notification (line 207);NotifyWorkerwas missing it.Change
private fun sendNotification(alert: CategoryAlert, ...) { + val openIntent = Intent(applicationContext, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP + } + val pendingIntent = PendingIntent.getActivity( + applicationContext, 0, openIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ) val notification = NotificationCompat.Builder(applicationContext, CHANNEL_ID) ... .setAutoCancel(true) + .setContentIntent(pendingIntent) .build() }Fixes #224