Android 是在 UI 线程还是其他线程中将 IntentService 运行 置于前台?

Does Android foreground IntentService run in the UI thread or a different thread?

我正在制作 IntentService。代码是这样的:

protected void onHandleIntent(@Nullable Intent intent) {
    startForeground(NOTIFICATION_ID, buildForegroundNotification());
}


private Notification buildForegroundNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), Integer.toString(NOTIFICATION_ID))
            .setContentTitle("App is running.")
            .setContentText("")
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    return (builder.build());
}

通常IntentService为其服务创建一个单独的工作线程。但在这里,我将此服务称为前台服务。此服务将在主 UI 线程上运行,还是创建一个单独的线程?

I am making an IntentService

请注意,IntentService 已弃用。

Will this service work on the main UI thread, or create a separate thread?

onHandleIntent() 将在后台线程上调用,无论您是否将其设为前台服务。