Restful API service

前端 未结 11 1600
清歌不尽
清歌不尽 2020-11-22 14:28

I\'m looking to make a service which I can use to make calls to a web-based REST API.

Basically I want to start a service on app init then I want to be able to ask t

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 15:19

    Lets say I want to start the service on an event - onItemClicked() of a button. The Receiver mechanism would not work in that case because :-
    a) I passed the Receiver to the service (as in Intent extra) from onItemClicked()
    b) Activity moves to the background. In onPause() I set the receiver reference within the ResultReceiver to null to avoid leaking the Activity.
    c) Activity gets destroyed.
    d) Activity gets created again. However at this point the Service will not be able to make a callback to the Activity as that receiver reference is lost.
    The mechanism of a limited broadcast or a PendingIntent seems to be more usefull in such scenarios- refer to Notify activity from service

提交回复
热议问题