两个意图服务是否会生成两个不同的工作线程?

Will two intent services generate two different worker threads or not?

我想用 IntentService 执行两个单独的后台任务,我想知道这两个意图服务是否会生成两个单独的工作线程,或者第二个将等待第一个完成。

例如

public class IntentServiceOne extends IntentService {
    public IntentServiceOne() {
        super("IntentServiceOne");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
       // code to execute
    }
}

public class IntentServiceSecond extends IntentService {
    public IntentServiceSecond() {
        super("IntentServiceSecond");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
       // code to execute
   }
}

来自 activity 的代码:

Intent intentOne=new Intent(this, IntentServiceOne.class);
startService(intentOne);
Intent intentSecond=new Intent(this, IntentServiceSecond.class);
startService(intentSecond);

多个IntentService可以同时运行。他们将在单独的线程上并行执行任务。你可以看看 - Can multiple Android IntentServices run at the same time?

Just i want to know both intent service will generate two saperate worker thread or second will wait for first to finish.

两者都会 运行 彼此独立。第二个 不会等待 第一个完成。 尽管每个 IntentService 将共享同一个工作实例。因此,假设如果您多次调用 startService(intentOne);,您对该特定服务的请求将得到 queued。来自 here.

All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), but only one request will be processed at a time.