Android Service interacting with multiple activities

前端 未结 2 2060
名媛妹妹
名媛妹妹 2020-12-09 06:08

I\'m trying to refactor/redesign an Android app. Currently, I\'ve one UI activity (Activity 1) that creates a DataThread. This thread is responsibl

2条回答
  •  情深已故
    2020-12-09 06:35

    Definitely more than one activity can bind to your service. You will get an onBind() for each one that binds. Your service would then ideally handle the logic of interacting with multiple activities by identifying them using an ID or the intent (with your own IDs for each activities as extras) from onBind() in your service. You could then have the Service spawn off a background thread for each activity that binded to it.

提交回复
热议问题