我有问题。我的服务有效,但是当我关闭应用程序服务时停止了。我如何才能让我的服务运行?
服务
[Service]
public class NotificationService : Service
{
public NotificationService () { }
public override StartCommandResult OnStartCommand (Android.Content.Intent intent, StartCommandFlags flags, int startId)
{
new Task(() =>
{
DoWork();
} ).Start();
return StartCommandResult.Sticky;
}
public override void OnDestroy ()
{
base.OnDestroy ();
}
public override IBinder OnBind (Intent intent)
{
throw new NotImplementedException ();
}
void DoWork()
{
new Task(() =>
{
for (int i = 0; i < 100; i ++)
{
System.Threading.Thread.Sleep(1000);
var context = Android.App.Application.Context;
var …Run Code Online (Sandbox Code Playgroud)