获取数据从服务到活动 [英] Getting data from the Service to the Activity

查看:140
本文介绍了获取数据从服务到活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

感谢了很多,

的Gratzi

解决方案
  

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

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

  

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

步骤#1:使用数据库

步骤#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.

这篇关于获取数据从服务到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆