From 4f59913d07ead01468b1b4ce84019ee4a8e9f1e5 Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Fri, 31 Aug 2018 15:30:44 +0200 Subject: [PATCH] Solving sleep bug. --- MusicApp/Resources/Portable Class/Sleeper.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MusicApp/Resources/Portable Class/Sleeper.cs b/MusicApp/Resources/Portable Class/Sleeper.cs index 7a5fadd..d3d6b5e 100644 --- a/MusicApp/Resources/Portable Class/Sleeper.cs +++ b/MusicApp/Resources/Portable Class/Sleeper.cs @@ -10,7 +10,7 @@ namespace MusicApp.Resources.Portable_Class public class Sleeper : Service { public static Sleeper instance; - public int timer; + public int timer = 0; public override IBinder OnBind(Intent intent) { @@ -24,12 +24,12 @@ namespace MusicApp.Resources.Portable_Class public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { - if (instance == null) - StartTimer(intent); + int time = intent.GetIntExtra("time", timer); + if (instance == null && time > 0) + StartTimer(time); else { NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService); - int time = intent.GetIntExtra("time", timer); if (time < 1) { notificationManager.Cancel(1001); @@ -51,10 +51,10 @@ namespace MusicApp.Resources.Portable_Class return StartCommandResult.Sticky; } - async void StartTimer(Intent intent) + async void StartTimer(int time) { instance = this; - timer = intent.GetIntExtra("time", 0); // In minutes + timer = time; // In minutes Intent mainActivity = new Intent(Application.Context, typeof(MainActivity)); Intent sleepIntent = new Intent(Application.Context, typeof(Player));