vendredi 29 décembre 2017

Xamarin Android C# Start Service 'else' not called

I have buttons that give the ability to start or stop the app's background service, but for some reason my 'else' call in the button's click event isnt being activated if the service is already running.

Heres the whole button code, hope someone knows why it doesnt call:

private void StartServiceButton_Click(object sender, EventArgs e)
    {
        if (Application.Context.GetSystemService("com.prg.NotificationService") == null)
        {
            Application.Context.StartService(intent);
        }
        else
        {
            Toast.MakeText(this, "Service already running)", ToastLength.Long).Show();
        }
    }

Aucun commentaire:

Enregistrer un commentaire