2017-10-13 5 views
0

私はIntentServiceで2つのサパーナルバックグラウンドタスクを行いたいと思います。だから、私は両方のインテントサービスが2つのsaperateワーカースレッドを生成するか、または2番目が最初に終了するのを待つことを知りたい。2つのインテントサービスは2つの異なるワーカースレッドを生成しますか?

Ex。活動から

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 
    } 
} 

コード:

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

答えて

1

ちょうど私が両方の目的のサービスをお知りになりたい2つのsaperate ワーカースレッドまたは第二を生成します終えることが最初のを待ちます。

両方とも互いに独立して動作します。第2のは、最初に完了するまでを待つことはありません。 各IntentServiceは同じワーカーインスタンスを共有します。したがって、startService(intentOne);に複数回お電話すると、この特定のサービスのリクエストはqueuedになります。 hereから。

すべての要求は、単一のワーカースレッドで処理されている - 彼らは必要な 限りがかかる場合があります(と、アプリケーションのメインループをブロックしません)、 一つだけの要求が一度に処理されます。

関連する問題