clq
浏览(597) +
2021-05-15 12:12:04 发表
编辑
关键字:
[2021-05-15 13:39:31 最后更新]
android 下服务未能启动的原因
1.
不是用 asd 生成的,没有在 AndroidManifest.xml 中写明。
2.
类没有实现全。
3.类写错了。
比较坑的是,并没有什么提示告诉你错在什么地方。
4.
AndroidManifest.xml 中写的类属性也很重要。比如
//---- test
Intent intent = new Intent(MainActivity.this, MyService.class);
//Intent intent = new Intent(MainActivity.this, xmpp1.class); //https://blog.csdn.net/zhang_jun_ling/article/details/51113924
startService(intent); //?? 没反应 //应该是没有在 AndroidManifest.xml 中写明
这段代码就只能启动 MyService2,启动不了 xmpp1
<service
android:name="net.newbt.service.MyService2"
android:enabled="true"
android:exported="true"></service>
<service
android:name="net.newbt.service.xmpp1"
android:process=":service1" /> <!-- 绑定一个服务类 -->
5.类的 onStartCommand 重载函数似乎是一个关键。
6.重启的方式
在 https://blog.csdn.net/qq_27061049/article/details/109366345
中说,可以在 onDestroy 中启动另外一个服务。不过这无法在划掉程序杀死时重启成功,只是在 “应用列表 -> 运行” 中停止后继续运行。
NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.