shinyorg / shiny

.NET Framework for Backgrounding & Device Hardware Services (iOS, Android, & Catalyst)
https://shinylib.net
MIT License
1.43k stars 227 forks source link

[Bug]: Click on notification poppup => 'This window is already associated with an active Activity (MauiShinyJobNotify.MainActivity). #1505

Closed TersaCA closed 1 month ago

TersaCA commented 1 month ago

Component/Nuget

Notifications (Shiny.Notifications)

What operating system(s) are effected?

Version(s) of Operation Systems

Andriod 14.0 api 34

Hosting Model

Steps To Reproduce

Expected Behavior

clicking on app should open or focus app

Actual Behavior

clicking causes exception

Exception or Log output

System.InvalidOperationException: 'This window is already associated with an active Activity (MauiShinyJobNotify.MainActivity). Please override CreateWindow on MauiShinyJobNotify.App to add support for multiple activities https://aka.ms/maui-docs-create-window or set the LaunchMode to SingleTop on MauiShinyJobNotify.MainActivity.'

Code Sample

    public class MyLocalNotificationDelegate : INotificationDelegate
    {
        readonly INotificationManager notificationManager;

        public MyLocalNotificationDelegate(INotificationManager notificationManager)
        {
            this.notificationManager = notificationManager;
        }

        public async Task OnEntry(NotificationResponse response)
        {
            notificationManager.Send("Note Click", $"Poppup Clicked at {DateTime.Now}");
        }
    }
    public class MyJob : Job
    {
        readonly INotificationManager notificationManager;
        readonly ILogger<MyJob> logger;

        public MyJob(ILogger<MyJob> logger, INotificationManager notificationManager) : base(logger)
        {
            this.logger = logger;
            this.notificationManager = notificationManager;
            MinimumTime = TimeSpan.FromSeconds(60);
        }

        protected override Task Run(CancellationToken cancelToken)
        {
            notificationManager.Send("Job Event", $"Job Completed at {DateTime.Now}" );
            return Task.CompletedTask;
        }
    }

Code of Conduct

aritchie commented 1 month ago

Share the solution please. People often tend to use old versions of the template or the library.

You can find the answer here on how this can be solved: https://github.com/dotnet/maui/issues/18692#issuecomment-2016524388

TersaCA commented 1 month ago

I believe everything is update. VS2022 was update yesterday. I uninstalled and reinstalled the shiny project template today and generated a new test project before posting the issue.

MauiShinyJobNotify.zip

munkii commented 1 month ago

@TersaCA

I was about to comment that we are also seeing this issue.

However I did some searching and came across others with a similar issue and a reply from @aritchie. Implementing his suggestion of setting an explicit LaunchActivityFlag worked for us,

aritchie commented 1 month ago

MAUI is talking about how they want to shift those flags around. I defaulted the flags to SingleTop in dev, but I'm not ready to release that right now

Please stick with the workaround listed above. You'll likely need to hard set this if MAUI shifts the flags in any case.