只有当myservice.java包含在类似于

com.test.app

,但不是像
com.test.app.services.MyService

在名单上我试着用
<service android:name=".services.MyService" />

或完全合格
<service android:name="com.test.app.services.MyService" />

但这两种方法都不管用。我正在使用子包以获得更好的文件结构。所以我真的可以不把我的服务文件放在一个子包里吗?或者我在这里遗漏了什么?
(我正在使用android团队提供的扩展下载程序库。这涉及到实现一个简单的服务。)

最佳答案

是的,你可以把它放在你想要的任何名称空间中。
除了子类化DownloaderService之外,您还需要阅读文档的其余部分,包括Starting the download。特别令人感兴趣的是这一行:

// Start the download service (if required)
int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
                pendingIntent, SampleDownloaderService.class);

注意,您需要在这里提供定制的Service类。

10-07 19:22
查看更多