when is smart to use bindService and when startService

前端 未结 2 854
Happy的楠姐
Happy的楠姐 2021-01-30 12:30

This may be a stupid question but I would like to know when it is smart to use bindService and when to use startService.

For example:

I

2条回答
  •  无人共我
    2021-01-30 13:18

    I agree with @Ovidiu Latcu but with one important note: when using bound services, the service is ended when the activity that started it is ended, (if it is the only activity bound to that service).

    So if you want to run your service at the background while the app is in the background, (the activity is paused for example and not visible to the user) then you must start the service without bounding to it and communicate with it with BroadcastReceiver for example.

提交回复
热议问题