小编Vun*_*nda的帖子

后台服务不工作 Xamarin.Android

我有问题。我的服务有效,但是当我关闭应用程序服务时停止了。我如何才能让我的服务运行?

服务

[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)

c# android xamarin

5
推荐指数
1
解决办法
939
查看次数

标签 统计

android ×1

c# ×1

xamarin ×1