Getting data from the Service to the Activity

前端 未结 2 940
被撕碎了的回忆
被撕碎了的回忆 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:20

    1) The simplest way to get Custom class data in Intent is, Get the data to primitive types then put this data by putString or whatever data type, then add a constructor to corresponding sent data to activity from set in custom object in activity.

    2) Other way of doing this is extend your custom class by parcelable and override corresponding methods then you will be able to send parcelable class object with intent. go to this link How to send an object from one Android Activity to another using Intents? for details

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题