【发布时间】:2014-11-04 23:05:49
【问题描述】:
我有一个包裹在 PendingIntent 中的 IntentService,我想在用户点击特定通知操作时启动它,如下所示:
Intent actionIntentService = new Intent(context, ActionIntentService.class);
PendingIntent actionPendingIntent = PendingIntent.getService(app, getNotificationId(), actionIntentService, PendingIntent.FLAG_CANCEL_CURRENT);
然后,我确保将具有此待处理意图的操作添加到通过 NotificationCompat.Builder 创建的通知中:
notificationBuilder.addAction(R.drawable.ic_notif_action, actionTitle, actionPendingIntent);
我的问题是,当
onHandleIntent(Intent intent)
调用了我的 IntentService 的方法,它在哪个线程上运行?
我已经调试了我的代码,它给我的印象是这个方法调用在主线程上运行。如果是这种情况,我该怎么做才能让它在后台线程上运行?
编辑:
我的 ActionIntentService 确实扩展了 IntentService
class ActionIntentService extends IntentService
【问题讨论】:
-
IntentService 在主 UI 线程之外运行(这就是重点)
标签: android multithreading android-intent android-notifications intentservice