public override void OnReceive(Context context, Intent intent) { var resultIntent = new Intent(context, typeof(MainActivity)); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var stackBuilder = TaskScheduler.Create(context); stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity))); stackBuilder.AddNextIntent(resultIntent); var chk = new ChecRunning(); if (!chk.isMyServiceRunning(typeof(BatteryService))) { Toast.MakeText(context, "Service Restarted!", ToastLength.Long).Show(); var backgroundServiceIntent = new Intent(context, typeof(BatteryService)); context.StartForegroundService(backgroundServiceIntent); } else { Toast.MakeText(context, "alarm tick!", ToastLength.Long).Show(); } //if (!initiate) //{ // BatteryBroadcastReceiver mReceiver = new BatteryBroadcastReceiver(); // context.RegisterReceiver(mReceiver, new IntentFilter(Intent.ActionBatteryChanged)); //} }
public override void OnReceive(Context context, Intent intent) { var chk = new ChecRunning(); if (!chk.isMyServiceRunning(typeof(BatteryService))) { Task.Delay(100); context.StartService(new Intent(context, typeof(BatteryService))); Toast.MakeText(context, "RestartSensor!", ToastLength.Short).Show(); } }