Service vs IntentService in the Android platform

后端 未结 11 608
挽巷
挽巷 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 03:57

    Service

    • Invoke by startService()
    • Triggered from any Thread
    • Runs on Main Thread
    • May block main (UI) thread. Always use thread within service for long task
    • Once task has done, it is our responsibility to stop service by calling stopSelf() or stopService()

    IntentService

    • It performs long task usually no communication with main thread if communication is needed then it is done by Handler or BroadcastReceiver
    • Invoke via Intent
    • Triggered from Main Thread
    • Runs on the separate thread
    • Can't run the task in parallel and multiple intents are Queued on the same worker thread.

提交回复
热议问题