Xamarin-Android Mvvmcross - clicking on the application that appears to launch notifications with a splash or bring to the fore

I am trying to create a neat solution for the following requirement:

a) When the user "selects" the notification that my application receives and the application is open and / or in the background, the application will be transferred to the font.

b) When the user β€œselects” the notification and the application closes, a pop-up window appears and the application starts as usual.

I try, but I have success with only one of the above options, not so sad. This is my code:

public void CreateNotification(string title, string desc, string pushUrl, string pushTitle) { var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext); setupSingleton.EnsureInitialized(); if (!string.IsNullOrWhiteSpace(pushUrl)) { var pushMessageParameterService = Mvx.Resolve<IPushMessageParameterService>(); pushMessageParameterService.SetPushActionParameters(new PushActionParameters { UrlToShow = pushUrl, ViewTitle = pushTitle }); } var intent = new Intent(this, typeof(SplashScreen)); intent.AddFlags(ActivityFlags.NewTask); intent.SetAction(Intent.ActionMain); intent.AddCategory(Intent.CategoryLauncher); //var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); //var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); var pendingIntent = PendingIntent.GetActivity(this, 0, intent.SetFlags(ActivityFlags.BroughtToFront), PendingIntentFlags.CancelCurrent); Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification); var notificationBuilder = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.Icon) .SetContentTitle(title) .SetContentText(desc) .SetAutoCancel(true) .SetSound(alarmSound) .SetContentIntent(pendingIntent); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); Notification notification = notificationBuilder.Build(); notification.Flags = NotificationFlags.ShowLights | NotificationFlags.AutoCancel; notificationManager.Notify(0, notification); } 

To keep it simple, I have two activities:

 public class SplashScreen : MvxSplashScreenActivity 

and

 public class DashboardView : BaseMvxActivity 

If I use "SplashScreen" as a PendingIntent for notification, and the application is already running / open / in the background, it freezes on the splashScreen screen. The MvvmCross log displays "Show ViewModel DashboardViewModel" but stops. OnCreate, Init, and Start are not called. The surge just remains.

If I use "DashboardView" as a PendingIntent for notification, and the application is closed / not active, I just see a white screen at startup and without a pop-up screen.

I would like to have the best of both worlds :). Therefore, when clicking on the push message and the application is open, just bring the application to the forefront (if it is not already). And when the application is closed, show the screen saver, etc. Etc.

I hope I put my question clear.

Thank you very much in advance.

+5
source share
1 answer

When I tried to use MvxSplashScreenActivity for my notification, it froze on this screen.

I pointed to the standard MvxActivity and set the background myself, as well as NoHistory = true in the Activity attribute. At OnCreate, in my pending activity, I start real intentions.

+1
source

Source: https://habr.com/ru/post/1237107/


All Articles