Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

OnStartCommand calling multiple time how to solve this?

$
0
0

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?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>