android - Intent 服务生命周期

标签 android service intentservice

我有一个处理对 Drupal 服务模块的异步调用的 IntentService。目前,我的 DrupalXmlRpcService 对象每次都在 onHandleIntent 中被初始化,因为我的印象是该服务会在线程完成后被终止。该对象是否应该在 IntentService 对象的构造函数中初始化?

最佳答案

如果您的 DrupalXmlRpcService 对象的创建成本很高并且您经常使用它,请考虑在全局 Application 对象中保存一个引用,或者可能使它成为一个单例(确保它是线程安全的)。至于你的问题,如果你向同一个服务发送多个 Intent , handleIntent() 可能会被调用多次,所以你可能想在构造函数中初始化(但如果花费的时间太长,可能会阻塞主线程)。

关于android - Intent 服务生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7438986/

相关文章:

java - Android:在多个 Activity 上传递字符串数组

android - 创建android子项目时出错,因为找不到路径

c# - 无法在 SlidingUpPanelLayout Xamarin Android 中使用 ScrollView 布局

Android Long-Service Create bg 线程,我不知道这是怎么回事

android - 如何从 Activity 中停止在另一个进程中启动的 Intent 服务

android - IntentService 中未收到广播接收器

java - 触发谷歌眼镜上的相机

android - 为什么服务在 BOOT_COMPLETED 后不启动?

Android:我应该使用什么来运行后台长期 Activity ?

android - 如何从 IntentService 收集信息并更新 Android UI