Getting data from the Service to the Activity

前端 未结 2 939
被撕碎了的回忆
被撕碎了的回忆 2021-02-11 10:01

In my application I have a service in which rss feeds are read. After the service finishes the reading I need to update my application and populate a list view with the download

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-11 10:29

    Using a broadcast receiver, and intents would not work, because the data is stored in a custom object.

    Then don't store the data in "a custom object".

    What is the best way to do that?

    Step #1: Use a database.

    Step #2: Alert the activity that there is new data in the database, via a broadcast Intent, or via a Messenger passed into the service, or via a PendingIntent created by createPendingResult() passed into the service, or via a ContentProvider facade and a content observer, etc.

    Step #3: Have the activity load the data out of the database, perhaps simply by calling requery() on an outstanding Cursor.

提交回复
热议问题