我有一个 IntentService 包裹在一个 PendingIntent 中,我想在用户点击特定的通知操作时启动它,如下所示:
Intent actionIntentService = new Intent(context, ActionIntentService.class);
PendingIntent actionPendingIntent = PendingIntent.getService(app, getNotificationId(), actionIntentService, PendingIntent.FLAG_CANCEL_CURRENT);
然后我确保将具有此待定 Intent 的操作添加到我通过 NotificationCompat.Builder 创建的通知中:
notificationBuilder.addAction(R.drawable.ic_notif_action, actionTitle, actionPendingIntent);
我的问题是,当
onHandleIntent(Intent intent)
调用了我的 IntentService 方法,它在哪个线程上运行?
我调试了我的代码,它给我的印象是这个方法调用在主线程上运行。如果是这样,我需要做什么才能让它在后台线程上运行?
编辑:
我的 ActionIntentService 确实扩展了 IntentService
class ActionIntentService extends IntentService
最佳答案
请引用文档,您描述的方法不存在。你应该扩展 IntentService并实现onHandleIntent(Intent)
文档说:
This method is invoked on the worker thread with a request to process.
关于android - Notification 操作启动的 IntentService 在哪个线程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26746756/