Android 如何停止 START_STICKY 服务

标签 android service

我的应用程序使用第三方库,该库启动了 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/

相关文章:

android - 如何确定状态栏是否在实现您的库的应用程序中是半透明的?

具有不同依赖项和相同类文件的 Android 风格

android - 在 Android Studio 中使用 Gradle 添加 Wire 依赖项的最佳方法

android - 安卓屏幕解锁后前台服务被杀死

android - 保持服务运行

android - AlertDialog 中的密码字段

java - 为什么这个 .equals() 不起作用?

windows - 如何获取 win32_service 恢复选项卡属性

Android:时间监听器

安卓服务定时器