示例#1
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            base.OnStartCommand(intent, flags, startId);

            Log.Debug(TAG, "restarting Service !!");
            counter = 0;

            // it has been killed by Android and now it is restarted. We must make sure to have reinitialised everything
            if (intent == null)
            {
                ProcessMainClass bck = new ProcessMainClass();
                bck.launchService(this);
            }

            // make sure you call the startForeground on onStartCommand because otherwise
            // when we hide the notification on onScreen it will nto restart in Android 6 and 7
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                restartForeground();
            }

            startTimer();

            // return start sticky so if it is killed by android, it will be restarted with Intent null
            return(StartCommandResult.Sticky);
        }
 protected override void OnResume()
 {
     base.OnResume();
     if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
     {
         restarter.RestartServiceBroadcastReceiver.scheduleJob(Application.Context);
     }
     else
     {
         ProcessMainClass bck = new ProcessMainClass();
         bck.launchService(Application.Context);
     }
 }