0

我裹着的PendingIntent的IntentService,我想,當用戶點擊一個特定的通知操作這樣的啓動:在哪個線程中通過Notification啓動的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); 

我的問題是,當m的

onHandleIntent(Intent intent) 

方法y IntentService被調用,它在哪個線程上運行?

我調試了我的代碼,它讓我覺得這個方法調用在主線程上運行。如果是這種情況,爲了使它在後臺線程上運行,我需要做些什麼?

編輯:

我ActionIntentService確實擴展了IntentService

class ActionIntentService extends IntentService 
+0

IntentService運行OFF主UI線程(即點) – Booger 2014-11-06 00:21:19

回答

1

請參考文檔,你所描述的方法不存在。您應該延伸IntentService和實施onHandleIntent(Intent)

文件說:

該方法被調用的工作者線程與處理請求。

+0

那麼什麼是問題?我想答案已經提供。 – 2014-11-06 00:23:32

+0

我的問題是爲什麼onHandleIntent()在通過點擊通知中的Action調用時在主線程上運行。 – murki 2014-11-06 01:22:11

+0

它沒有。你怎麼知道?你如何檢查? – 2014-11-06 01:30:42