[英]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 线程上工作,还是创建一个单独的线程?
我正在制作一个 IntentService
请注意,不推荐使用IntentService
。
这个服务会在主 UI 线程上工作,还是创建一个单独的线程?
onHandleIntent()
将在后台线程上调用,无论您是否将其设为前台服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.