Multiple IntentService or one Service

后端 未结 3 437
醉话见心
醉话见心 2021-01-31 10:36

I\'m a little confused on the difference between IntentService and Service. I understand that IntentService has a worker queue, but is there any benefit to using multiple Intent

3条回答
  •  轮回少年
    2021-01-31 11:21

    IntentService is just a convenient class to write services that are workers in the producer-consumer pattern. They are services designed to execute various tasks in a row and then stop. Services are not necessarily IntentServices such as services that must stay alive such as daemons.

    So you should wonder if you service is close to a worker thread, if so, use IntentServices else just derive from Service.

    Your second questions was whether to group all 3 services in a 3 in 1 service. The answer is that it depends how you use your datasources : if you use them altogether, then group them in a single service. If they are used separately, you could build a service for each with the hope to provide a lighter service if only one datasource is used and not the other. But if you use all 3 datasources, each in a service, then it will be heavier than using a single service.

提交回复
热议问题