I have made a background service in my project. How can I keep the background service alive?
I use the following code:
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
ambil_jam();
return StartCommandResult.Sticky;
}
However, it only keeps it alive when I close the app and when I try to clear the RAM the background service closed.
I also use this:
[Register("onTaskRemoved", "(Landroid/content/Intent;)V", "GetOnTaskRemoved_Landroid_content_Intent_Handler")]
public virtual void OnTaskRemoved()
{
StartService(new Intent(this, typeof(SimpleService)));
}
However, it is never called when I close my app. Does the method onTaskRemoved()
override, or do I need to call it again?
I'm using Xamarin.Android.