android - Notification 操作启动的 IntentService 在哪个线程中运行?

标签 android multithreading android-intent android-notifications intentservice

我有一个 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/

相关文章:

android - Unresolved reference 'Intent' : val intent = Intent

android - 静态对象在 Android 上保留它们的实例多长时间?

c++ - Win32 事件与信号量

java - 我们如何获得NPE,race condition

java - 在新线程中 toast

java - 从方法开始 Activity

android - 在 Android 中启动 Activity 时出现 ArrayIndexOutOfBoundsException

java - 我有一项 Activity 。在此 Activity 中,我执行了 AsyncTask ,但它不起作用

java - Handler 可以返回 Future 对象吗?

android - 使用SwipeRefreshLayout实现Pull to Refresh的一些问题