mistrypragnesh40 / PushNotificationDemoMAUI

33 stars 10 forks source link

Error When clicking on Notification while the application is opened #2

Closed mmeissa closed 1 year ago

mmeissa commented 1 year ago

I solved the Error problem mentioned in the video (minuet 38:22) To solve the error problem mentioned in the video you need to to set the MainActivity LaunchMode to SingleTop like this: [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges =........ This will eliminate the error.

Then to handle the data when the application is already running you need to add the following: 1- Check if data is added to preferences in OnAppearing() event of MainPage by overriding the method, because the constructor will not be called if there is already an instance of the page.

2- Add the data to the preferences in the OnNewIntent() event of MainActivity by overriding the method in MainActivity because OnCreate will not be called if the application is already running.

Hope this will be helpful to everyone

mistrypragnesh40 commented 1 year ago

Thank you so much for your help. I have updated the code.