IntentService 類別提供簡單明瞭的執行結構
    在單一背景執行緒上處理一項作業以便處理長時間執行的作業
    且不會影響使用者介面的反應速度此外,
    IntentService 未受大部分的使用者介面生命週期事件影響,因此
    在停止 AsyncTask 的情況下繼續執行
    IntentService 具有下列限制:
- 
        無法直接與使用者介面互動,如要將結果放在 UI 中,您
        都必須傳送至 Activity。
- 
        工作要求會依序執行。如果作業在
        IntentService,如果您另外傳送要求,則該要求會等待至 第一個作業就完成
- 
        在 IntentService上執行的作業無法中斷。
    不過在大多數情況下,建議您使用 IntentService 執行
    簡單的背景作業
本指南說明如何執行下列操作:
- 建立您自己的 IntentService子類別。
- 建立必要的回呼方法 onHandleIntent()。
- 定義 IntentService。
處理傳入意圖
    如要為應用程式建立 IntentService 元件,請定義會用來
    可擴充 IntentService,然後在當中定義
    覆寫 onHandleIntent()。例如:
Kotlin
class RSSPullService : IntentService(RSSPullService::class.simpleName) override fun onHandleIntent(workIntent: Intent) { // Gets data from the incoming Intent val dataString = workIntent.dataString ... // Do work here, based on the contents of dataString ... } }
Java
public class RSSPullService extends IntentService { @Override protected void onHandleIntent(Intent workIntent) { // Gets data from the incoming Intent String dataString = workIntent.getDataString(); ... // Do work here, based on the contents of dataString ... } }
    請注意,一般 Service 元件的其他回呼,例如
    onStartCommand() 會自動叫用
    IntentService。在 IntentService 中,應避免
    以覆寫這些回呼
如要進一步瞭解如何建立 IntentService,請參閱擴充
IntentService 類別。
在資訊清單中定義意圖服務
    IntentService 也需要應用程式資訊清單中的項目。
    以此身分提供這個項目
    <service>
    該元素的子項
    
    <application> 元素:
<application android:icon="@drawable/icon" android:label="@string/app_name"> ... <!-- Because android:exported is set to "false", the service is only available to this app. --> <service android:name=".RSSPullService" android:exported="false"/> ... </application>
    android:name 屬性會指定
    IntentService。
    請注意,
    <service>
    元素並未包含
    「意圖篩選器」。
    如果 Activity 將工作要求傳送至服務,就會使用
    明確 Intent,因此不必使用篩選器。這也
    換言之,只有相同應用程式或其他應用程式中的元件,具有
    才能存取服務
    您已瞭解基本的 IntentService 類別,現在可以傳送工作要求了
    加入 Intent 物件建構這些物件的程序
    以及如何將這類電子郵件傳送到您的 IntentService,詳情請參閱
    將工作要求傳送至背景服務。
