gpt4 book ai didi

Android 如何停止 START_STICKY 服务

转载 作者:太空狗 更新时间:2023-10-29 14:58:42 28 4
gpt4 key购买 nike

我的应用程序使用第三方库,该库启动了 START_STICKY 服务。所以即使应用被销毁,服务被杀死,它也会自动重启。

我的问题是,有什么方法可以像更改应用程序一样更改此服务生命周期吗?服务在应用启动时启动,服务在应用停止时停止。

最佳答案

在 list 文件中向该服务添加一个intent Filter

 <service
android:name="ServiceName"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="IntentName"/>
</intent-filter>
</service>

然后使用此 Intent 在您想要的任何地方启动或停止服务

String intentName="IntentName";
Intent i=new Intent(itentName);
context.stopService(i);

context.startService(i);

关于Android 如何停止 START_STICKY 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28961419/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com