Android Service System使用start Sticky重启服务时调用哪个方法

标签 android android-service

根据此处的 Android 文档:

https://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent, int, int)

onStartCommand() 仅在用户明确启动服务时触发

当系统启动使用START_STICKY启动的服务时调用哪个方法?

最佳答案

将重新创建服务

onCreate()onStartCommand() 都会被调用。

来自documentation :

Later the system will try to re-create the service. Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after creating the new service instance; if there are not any pending start commands to be delivered to the service, it will be called with a null intent object, so you must take care to check for this.

关于Android Service System使用start Sticky重启服务时调用哪个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992838/

相关文章:

java - Android Studio 单元测试 SQLiteDataBase 为空

Android - 处理内部存储中的文件

android - 条码扫描

android - 如果应用程序在后台运行,则丢失网络 android 6 及更高版本

Android Pie - 隔夜服务一直被杀死

android- 从内部类调用 Intent

android - 添加 Facebook 登录时应用程序崩溃

android - 如何将数据从 IntentService 发送到 Non-Activity 类

android - 同一 Intent 服务并行运行多个后台任务(问题)

android - Activity 未收到来自服务的本地广播