Why use Service if it runs in the same thread in android

前端 未结 3 1593
我寻月下人不归
我寻月下人不归 2020-12-13 13:05

I was going through Bound Service in Android Developer website. I thought I understood the service enough but I just found another way of connecting service through Using a

3条回答
  •  臣服心动
    2020-12-13 13:30

    Service basically runs in UI thread or main thread.But,if we are going to perform long running operations in service,we need to create a background thread and perform that task.

    But why we have to use service?

    Now let's think of Music Application.We need songs to be played continuously even if we leave music app.If we use activities,we can't achieve above requirement.So,service helps in these kind of scenarios.Even if the app is not in foreground, service keeps on running and we are able to listen to songs.This is why we use service even though it runs on main thread.

提交回复
热议问题