I manage an ONGOING notification from my application (not from a service).
When I kill application from task manager with \"End\" button, no
I wanted to close all my App notifications,remove badge icons on Logout, removed from recent app list . so for
Xamarin.Android
start service at launcher activity(i am creating notification from here) as
Intent intent = new Intent(this, typeof(PushNotificationService));
this.StartService(intent);
where PushNotificationService
is my Android service
inside which i have
[Service]
public class PushNotificationService : Service
{
public override IBinder OnBind(Intent intent)
{
return null;
}
public override void OnCreate()
{
base.OnCreate();
}
public override void OnTaskRemoved(Intent rootIntent)
{
try
{
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Cancel(0);
ME.Leolin.Shortcutbadger.ShortcutBadger.RemoveCount(Application.Context);
}
catch (System.Exception ex)
{
}
}
}
this line in OnTaskRemoved(Intent rootIntent)
did the trick
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Cancel(0);
where 0 in notificationManager.Cancel(0);
is the local notifcation id which we put at the time of building notification.