我正在制作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线程上运行,还是创建一个单独的线程?
我正在制作IntentService
注意IntentService
已过时。
此服务将在主UI线程上运行,还是创建一个单独的线程?
[onHandleIntent()
将在后台线程上被调用,无论您是否使其成为前台服务。