Service vs IntentService in the Android platform

后端 未结 11 832
挽巷
挽巷 2020-11-22 03:38

I am seeking an example of something that can be done with an IntentService that cannot be done with a Service (and vice-versa)?

I also bel

11条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 04:13

    Android IntentService vs Service

    1.Service

    • A Service is invoked using startService().
    • A Service can be invoked from any thread.
    • A Service runs background operations on the Main Thread of the Application by default. Hence it can block your Application’s UI.
    • A Service invoked multiple times would create multiple instances.
    • A service needs to be stopped using stopSelf() or stopService().
    • Android service can run parallel operations.

    2. IntentService

    • An IntentService is invoked using Intent.
    • An IntentService can in invoked from the Main thread only.
    • An IntentService creates a separate worker thread to run background operations.
    • An IntentService invoked multiple times won’t create multiple instances.
    • An IntentService automatically stops after the queue is completed. No need to trigger stopService() or stopSelf().
    • In an IntentService, multiple intent calls are automatically Queued and they would be executed sequentially.
    • An IntentService cannot run parallel operation like a Service.

    Refer from Here

提交回复
热议问题