I am working on a simple service in my app that also dispatches a notification to show the user, that the service is running. This DID work but stopped from one day to the other. I know that the code is beeing called right. I set a testing toast in within those lines and that is getting called every half second, so it should work but no notificaion shows up in the notification bar. Please have a look:
void DispatchNotificationThatServiceIsRunning()
{
_notificationIsLive = true;
RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.Notification);
contentView.SetTextViewText(Resource.Id.txt_crrentSong_notification, Activity_Player.txt_CurrentSong.Text);
contentView.SetTextViewText(Resource.Id.txt_crrentSong__artist_notification, Activity_Player.txt_CurrentArtist.Text);
notificationBuilder = new Notification.Builder(this);
Task.Delay(_countDownFirstRound).ContinueWith(t =>
{
notificationBuilder
.SetSmallIcon(Resource.Drawable.btn_icon_header)
.SetCustomContentView(contentView);
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(50, notificationBuilder.Build());
DispatchNotificationThatServiceIsRunning();//This is for repeate every 1s.
_countDownFirstRound = 50;
// Click on notification, and return to app. Only works, because _2TimerRunning is set as : "LaunchMode = LaunchMode.SingleInstance"
Intent notificationIntent = new Intent(this, typeof(Activity_Player));
notificationIntent.SetAction(Intent.ActionMain);
notificationIntent.AddCategory(Intent.CategoryLauncher);
PendingIntent contentIntent = PendingIntent.GetActivity(this, 1, notificationIntent, PendingIntentFlags.UpdateCurrent);
notificationBuilder.SetContentIntent(contentIntent);
},
TaskScheduler.FromCurrentSynchronizationContext());
}
}