在android应用程序的后台服务中强制关闭
你好。我按照本教程创建了一个后台服务应用程序 http://androidsourcecode .blogspot.com/2010/10/basic-android-background-service.html。但我的清单文件有错误。
错误消息
The element type "category" must be terminated by the matching end-tag "</category>".
我不知道如何创建 Android 后台服务。对此的任何指导表示赞赏。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.javaorigin.android.sample.service" android:versionCode="1"
android:versionName="1.0">
<application icon="@drawable/icon" label="@string/app_name">
<service class=".MyService" name=".MyService">
<intent-filter>
<action android:value="com.javaorigin.android.sample.service.MY_SERVICE"
android:name=".MyService" />
</intent-filter>
</service>
<activity android:name=".SampleAction"
android:label="@string/app_name">
<intent-filter>
<action name="android.intent.action.MAIN">
<category name="android.intent.category.LAUNCHER">
</intent-filter>
</activity>
Hi. I have create a background service application following this tutorial http://androidsourcecode.blogspot.com/2010/10/basic-android-background-service.html. But I have an error in the manifest file.
Error Message
The element type "category" must be terminated by the matching end-tag "</category>".
I don't know how to create an Android background service. Any guidance on that is appreciated.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.javaorigin.android.sample.service" android:versionCode="1"
android:versionName="1.0">
<application icon="@drawable/icon" label="@string/app_name">
<service class=".MyService" name=".MyService">
<intent-filter>
<action android:value="com.javaorigin.android.sample.service.MY_SERVICE"
android:name=".MyService" />
</intent-filter>
</service>
<activity android:name=".SampleAction"
android:label="@string/app_name">
<intent-filter>
<action name="android.intent.action.MAIN">
<category name="android.intent.category.LAUNCHER">
</intent-filter>
</activity>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的清单文件没有大问题。该教程看起来很旧,您需要做一些更改才能消除错误。就像使用正斜杠结束操作和类别标签一样,不要使用 android:name 属性名称,而是将 use-sdk 移到应用程序标签之前(Lint 更喜欢这样做)。就是这样 !
试试这个:
There is no big problem in your manifest file. That tutorial seems like old and you need to do few changes to get rid of errors. Like the forward slashes to end action and category tag, instead of attribute name use android:name, move the uses-sdk before application tag(where Lint prefer it). Thats it !
Try This :
它与 Service 元素无关。您的 XML 格式错误;任何不包含嵌套元素的标签必须在同一行上以斜杠终止。这是更正后的块:
注意 MAIN 和 LAUNCHER 之后的斜杠。如果没有这些,解析器会认为您将标签保持打开状态,以便在其下面嵌套子级。
It's not related to the Service element. Your XML is malformed; any tags that do not contain nested elements must terminate on the same line with a slash. Here is the corrected block:
Note the slashes after MAIN and LAUNCHER. Without these, the parser thinks you are leaving the tag open to nest children underneath it.
将其复制粘贴到您的清单中:
Copy paste this in your manifest: