-
Notifications
You must be signed in to change notification settings - Fork 473
Fix clicking on notification does not restore activity #2979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
08a60f1
da52de7
2f19f84
7167731
aac25e2
6f66f09
392c350
9fbc11a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -157,11 +157,12 @@ void StartForegroundServices() | |||||||||
| { | ||||||||||
| NotificationManager ??= GetSystemService(NotificationService) as NotificationManager ?? throw new InvalidOperationException($"{nameof(NotificationManager)} cannot be null"); | ||||||||||
| notificationBuilder ??= new NotificationCompat.Builder(Platform.AppContext, "1"); | ||||||||||
|
|
||||||||||
| var pendingIntent = CreateActivityPendingIntent(); | ||||||||||
| notificationBuilder.SetSmallIcon(Resource.Drawable.media3_notification_small_icon); | ||||||||||
| notificationBuilder.SetAutoCancel(false); | ||||||||||
| notificationBuilder.SetForegroundServiceBehavior(NotificationCompat.ForegroundServiceImmediate); | ||||||||||
| notificationBuilder.SetVisibility(NotificationCompat.VisibilityPublic); | ||||||||||
| notificationBuilder.SetContentIntent(pendingIntent); | ||||||||||
|
|
||||||||||
| CreateNotificationChannel(NotificationManager); | ||||||||||
|
|
||||||||||
|
|
@@ -177,4 +178,17 @@ void StartForegroundServices() | |||||||||
| StartForeground(1, notificationBuilder.Build()); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static PendingIntent CreateActivityPendingIntent() | ||||||||||
| { | ||||||||||
| var packageName = Platform.AppContext.PackageName ?? throw new InvalidOperationException("PackageName cannot be null"); | ||||||||||
| var packageManager = Platform.AppContext.PackageManager ?? throw new InvalidOperationException("PackageManager cannot be null"); | ||||||||||
| var launchIntent = packageManager.GetLaunchIntentForPackage(packageName) ?? throw new InvalidOperationException("Launch intent cannot be null"); | ||||||||||
|
|
||||||||||
| launchIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop); | ||||||||||
|
|
||||||||||
| var flags = PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable; | ||||||||||
|
||||||||||
| var flags = PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable; | |
| var flags = OperatingSystem.IsAndroidVersionAtLeast(31) | |
| ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable | |
| : PendingIntentFlags.UpdateCurrent; |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the project's coding guidelines, null checking should use the is pattern instead of the null-coalescing operator with throw. Consider refactoring this null check to use pattern matching for consistency with the codebase standards.
For example, instead of:
return PendingIntent.GetActivity(Platform.AppContext, 0, launchIntent, flags) ?? throw new InvalidOperationException("PendingIntent cannot be null");Use:
if (PendingIntent.GetActivity(Platform.AppContext, 0, launchIntent, flags) is not { } pendingIntent)
{
throw new InvalidOperationException("PendingIntent cannot be null");
}
return pendingIntent;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the project's coding guidelines, null checking should use the
ispattern instead of the null-coalescing operator with throw. Consider refactoring these null checks to use pattern matching for consistency with the codebase standards.For example, instead of:
Use:
This pattern should be applied to all three null checks in this method (PackageName, PackageManager, and the launch intent).