2017-10-13 40 views
0

我想用IntentService做兩個saperate後臺任務。所以,只是我想知道這兩個intent服務會生成兩個saperate工作線程或第二個將等待第一個完成。兩個intent服務會生成兩個不同的worker線程嗎?

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

只是我想知道,這兩個目的服務將產生兩個saperate 工作線程或第二將等待第一個完成。

兩者都可以獨立運行。第二不會等待首先完成。 雖然每個IntentService將共享相同的工人實例。因此,假設您多次致電startService(intentOne);,您對此特定服務的請求獲得queued。從here

的所有請求都在一個工作線程處理 - 他們可能會採取只要有必要 (並不會阻止該應用程序的主循環), 但只有一個請求將在同一時間進行處理。

相關問題