【发布时间】:2018-02-09 20:59:56
【问题描述】:
大家好,我在测试中遇到了这个问题,我一直在寻找信息,但目前找不到任何解决方案。我遵循了服务指南,并按照指南所说的做了,但仍然遇到问题。
我的服务代码:
[Service(Label="MyService")]
public class MyService : Service{
protected override StartCommandResult onStartCommand(Intent intent, StartCommandFlags flags, int startId){
var t = new Task(() => {
Looper.prepare();
do{
DoServiceWork();
while(running);
});
t.Start();
return StartCommandResult.Sticky;
}
}
在我的主要活动中:
protected override void OnCreate(Bundle bundle){
new Task(StartService).Start();
}
void StartService(){
var intent = new Intent(Application.Context, typeof(MyService));
Application.Context.StartService(intent);
}
当我的应用程序被杀死时,我无法让我的服务继续工作,我希望你们能帮助我解决这个问题,提前感谢那些可以帮助我的人。
【问题讨论】:
-
您是否在清单中注册了您的服务?
-
@codeMagic,感谢您的指导,将删除。我想也许,我们需要看到一条错误消息。
-
@Daniel 没问题。但是,如果您认为我错过了一些错误,请随时添加。我不是总是对;)
-
@ChrisStillwell 当你用服务属性装饰服务类时,它会自动注册,
标签: android service xamarin.forms android-service background-service