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
Post a Comment