Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to get Xamarin.Android App to run in background when app is closed

I want to make a App that shows a notification when the Speaker is muted. For this i somehow need to get a System.Timers Timer running in the background even if i close the app in the Task Manager. I already tried making a service but as soon as I close the app in Task Manager the Service stops. I'm new to Xamarin btw :D Here's my Service:

[Service]
public class SimpleStartedService : Service
{


    Timer timer;



    bool notifShown = false;
    bool isStarted = false;

    public override void OnCreate()
    {
        base.OnCreate();
    }

    public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
    {

        if (isStarted)
        {
        }
        else
        {
            timer = new Timer(2000);
            timer.Enabled = true;
            timer.Elapsed += TimerEvent;
            isStarted = true;
        }
        return StartCommandResult.Sticky;
    }

Comments