android - 如何停止 android Background IntentService?

标签 android android-intent intentservice

我的要求很简单。

我有一个简单的应用程序。 2 个按钮。和 1 项服务。 条件: Button1 单击,-> 启动 IntentService。Button2 单击 -> 停止 IntentService。

第一部分工作正常。我可以使用 startService(intent) 命令启动 IntentService。 但是,我无法停止 IntentService。即,stopService(intent) 命令不起作用。 它既不抛出错误也不做任何事情。

谁能解释一下这个??

我搜索并找到了这个问题 How to stop an IntentService? 但它不能满足我的需求。

最佳答案

您不能手动停止 IntentServiceIntentService 将在该服务不再有要处理的 Intent 时自动停止。

如果您想通过单击按钮来停止服务,请使用普通的服务

关于android - 如何停止 android Background IntentService?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28010257/

相关文章:

android - RecyclerView 中的复选框选择重复

android - 打开谷歌地图应用并在flutter webview中显示逐向导航

java - 调用虚方法 null context.getSystemService

android - IntentService 或 JobScheduler 在 onPause 期间执行 I/O 密集型数据保存操作

android - 将图标添加到 Android 抽屉导航?

java - 无法从 Android 中的远程服务器下载 .apk 文件

Android:从小部件打开错误的 Activity

android - 加载数据后隐藏 ProgressDialog

android - Cordova 图标和闪屏不工作

android - 广播接收器没有收到 Intent