Notify activity from service

后端 未结 4 1077
予麋鹿
予麋鹿 2020-11-28 04:10

I\'m trying to start a Service from my Activity to look out for changes on a web page, it\'s a private app so I don\'t bother the battery life...

4条回答
  •  执念已碎
    2020-11-28 05:03

    As Alex indicated, you can bind to the service and pass some sort of listener or callback to the service to use on events.

    Or, you can use a broadcast Intent, perhaps using methods like setPackage() on the Intent to limit the scope of the broadcast.

    Or, you can use createPendingResult() to create a PendingIntent that you pass as an Intent extra to the service -- the service can then use that PendingIntent to trigger onActivityResult() in your activity.

    Or, you can use a ResultReceiver.

    Or, you can use a Messenger.

    (admittedly, I have not tried those latter two approaches, but I think they will work here)

提交回复
热议问题