Android前景IntentService是否在UI线程或其他线程中运行?

问题描述 投票:0回答:1

我正在制作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线程上运行,还是创建一个单独的线程?

android android-intentservice foreground-service
1个回答
0
投票

我正在制作IntentService

注意IntentService已过时。

此服务将在主UI线程上运行,还是创建一个单独的线程?

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

© www.soinside.com 2019 - 2024. All rights reserved.