获取数据从服务到活动数据

2023-09-05 05:15:19 作者:十年很久你们别走

在我的应用我有一个服务,其中的RSS源中读取。服务结束后,我需要更新我的应用程序,并填充列表视图下载的信息的读取。使用广播接收器,并且意图是行不通的,因为数据被存储在自定义对象。什么是做到这一点的最好方法是什么?

感谢了很多,

的Gratzi

解决方案   

使用广播接收机,并且意图是行不通的,因为该数据被存储在自定义对象

那就不要存放在自定义对象的数据。

  

什么是做到这一点的最好方法是什么?

步骤#1:使用数据库

如何使用C 实现用户登陆后读取用户数据及动态保存用户数据

步骤#2:提醒的活动,有一个在数据库中的新数据,通过广播意图,或通过使者传递到服务,或通过 PendingIntent createPendingResult创建()传递到服务,或通过的ContentProvider 的外观和内容的观察员等。

第三步:有活动负载中的数据从数据库中,或许仅仅通过调用重新查询()的有关未决光标

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 downloaded information. Using a broadcast receiver, and intents would not work, because the data is stored in a custom object. What is the best way to do that?

Thanks a lot,

Gratzi

解决方案

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.