My background service class call OnStartCommand first time:
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
StartServiceInForeground();
Device.StartTimer(TimeSpan.FromMinutes(1), () =>
{
DependencyService.Get<ISQLite>().GetLocalNotification("Message", GlobalVariables.SellerUserName);
return true;
return StartCommandResult.Sticky;
}
void StartServiceInForeground()
{
isStartForeground = true;
var ongoing = new Notification(Resource.Drawable.AppLogo, "Notification");
var pendingIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), 0);
ongoing.SetLatestEventInfo(this, "Notification", "SimpleService is running in the foreground", pendingIntent);
StartForeground((int)NotificationFlags.AutoCancel, ongoing);
}
my application runs on foreground even I remove it on swipe.
while open the app second time then OnStartCommand calling again.
here is my code for calling background service from mainActivity
Intent intent = new Intent(this, typeof(BackgroundService));
StartService(intent);
how to solve this issue for onstartcommand calling multiple time?