android - 如果我不调用 stopService() 或 stopSelf() 方法,服务何时停止

标签 android android-service

If you start a service by calling startService() then you have to call stopService() or stopSelf() to stop the service. If you want to stop a service after doing some work, you might want to use IntentService instead.`

如果我没有使用IntentService,那么如果我不调用stopService()stopSelf(),服务何时停止方法?

最佳答案

If I am NOT using IntentService then when will service stop if I don't call stopService() or stopSelf() methods?

如果您的服务是通过 startService() 启动的,并且您没有调用 stopService()stopSelf(),您的服务将被视为“正在运行”,直到您的进程终止。作为此过程的一部分,您可能会或可能不会被调用 onDestroy(),具体取决于您的进程的系统 RAM 的需求有多紧急。

如果从 onStartCommand() 返回 START_STICKYSTART_REDELIVER_INTENT,您的进程和服务应该会在某个时间自动重新启动在不久的将来,当 RAM 需要允许时。

关于android - 如果我不调用 stopService() 或 stopSelf() 方法,服务何时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35503886/

相关文章:

java - 套接字连接需要android应用程序锁吗?

android - 试图设置 MultiDexApplication , ClassCastException

android - Canvas坐标系的单位是什么? - 安卓

android - 将上下文传递给 JobService Android JobScheduler

android - ADB is not working and failed to initialize monitor thread 错误发生在android中的ddms

android - 如何与服务器执行android应用程序同步?

android - 获取正在运行的进程列表并终止特定进程

android - Root设备的 INJECT_EVENTS 权限

javascript - 如何打开 map Activity 并从另一个 Activity 设置位置?

android - 通过使用通知操作按钮以编程方式在 android 通知的大 View 和普通 View 之间切换