private async Task <Intent> GetContentIntentAsync(NotificationsHelperBase notificationHelper, TaskStackBuilder taskStackBuilder)
        {
            bool loginExpired = !(await new LoginService().GetLoginValidityAsync());

            ISalesAppSession session = Resolver.Instance.Get <ISalesAppSession>();

            if (loginExpired || session == null || session.UserId == default(Guid))
            {
                return(new Intent(AppContext, typeof(LoginActivityView)));
            }
            else
            {
                Logger.Debug("Session id is " + session.UserId);
                DestinationInformation destinationInformation = notificationHelper.GetDestinationInformation();
                taskStackBuilder.AddParentStack(Class.FromType(destinationInformation.ActivityType));
                taskStackBuilder.AddNextIntent(destinationInformation.ContentIntent);
                return(destinationInformation.ContentIntent);
            }
        }
        public override void OnReceive(Context context, Intent intent)
        {
            Task.Run
            (
                async() =>
            {
                try
                {
                    // Wakelocker.Acquire(AppContext, WakelockTag);
                    // await new LocalOtaService().CacheAsync();
                    Logger.Debug("Notification OnReceive called");
                    int savedNotificationType = intent.GetIntExtra(NotificationType, 0);
                    if (savedNotificationType == 0)
                    {
                        Logger.Error("Unknown notification type");
                        return;
                    }
                    Logger.Debug("Notification type is " + savedNotificationType);
                    NotificationTypes notificationType = (NotificationTypes)savedNotificationType;
                    Logger.Debug("Showing notification of type " + notificationType.ToString());


                    if (notificationType == default(NotificationTypes))
                    {
                        return;
                    }



                    Logger.Debug("Booting up the core notification service");
                    NotificationsCoreService notificationsCoreService = new NotificationsCoreService();
                    Logger.Debug("Requesting core notification service for overdue notifications");
                    List <string> overdueNotifications =
                        await notificationsCoreService.GetOverdueNotificationsEntityIdsAsync(notificationType);

                    Logger.Debug("Establishing the notification helper to use");
                    NotificationsHelperBase notificationHelper = GetHelper(notificationType);

                    Logger.Debug("Asking notification helper to filter out notifications that aren't needed");
                    await notificationHelper.SetOverdueNotificationsAsync(overdueNotifications);

                    if (overdueNotifications == null)
                    {
                        overdueNotifications = new List <string>();
                    }
                    if (overdueNotifications.Count == 0)
                    {
                        Logger.Debug("Turns out there are no notifications to show");

                        return;
                    }


                    string message = notificationHelper.GetMessage();
                    PendingIntent contentIntent = PendingIntent.GetActivity(context, default(int), intent,
                                                                            PendingIntentFlags.CancelCurrent);



                    var notificationManager = NotificationManagerCompat.From(context);
                    var style = new NotificationCompat.BigTextStyle();
                    style.BigText(message);


                    var builder = new NotificationCompat.Builder(AppContext)
                                  .SetContentTitle(notificationHelper.GetTitle())
                                  .SetContentText(notificationHelper.GetMessage())
                                  .SetAutoCancel(notificationHelper.AutoCancel)
                                  .SetContentIntent(contentIntent)
                                  .SetSmallIcon(Resource.Drawable.Icon22x22)
                                  .SetStyle(style)
                                  .SetDefaults((int)notificationHelper.SoundAndOrVibrationAndOrLights)
                                  .SetWhen(JavaSystem.CurrentTimeMillis());

                    TaskStackBuilder taskStackBuilder = TaskStackBuilder.Create(AppContext);
                    Intent destIntent = await GetContentIntentAsync(notificationHelper, taskStackBuilder);

                    if (destIntent != null)
                    {
                        PendingIntent pendingIntent = taskStackBuilder.GetPendingIntent(0,
                                                                                        PendingIntentFlags.OneShot);
                        //PendingIntent.GetActivity(AppContext, 0, destIntent, PendingIntentFlags.OneShot);
                        builder.SetContentIntent(pendingIntent);
                    }
                    var notification = builder.Build();
                    notificationManager.Notify((int)notificationType, notification);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    throw;
                }
                finally
                {
                    Wakelocker.Release();
                }
            }
            );
        }