刷新的活动,从服务活动时, [英] Refreshing an Activity from service when Active

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

问题描述

我有一个应用程序,我希望更新的活动(活动目录是precise),只有当从服务的活动是在前台(活动)

我可以使用ListActivity意图,但问题是这引起了活性,即使在后台的。

我也考虑过使用registerDataSetObserver上ListAdapter但强制要求光标应该进行更新。更新来自外部服务的游标可能是不可行的。

我们有一个通用的解决办法?

解决方案
  

我们有一个通用的解决方案,这   ?

他们可能一打。这里有几个:

  • 有活动注册服务的侦听器对象的 onResume()的onPause将其删除()
  • 发送私人广播,拾起活动通过 registerReceiver()时,它是在前台
  • 有活动提供一个等待结果式的 PendingIntent 到服务
  • 使用一个 ResultReceiver
  • 使用一个的ContentProvider ,与该活动举办到光标从供应商,服务更新提供者

这套方案演示了前三,在远程服务范围内。

I've an app where I wish to update the Activity (List activity to be precise) only when the activity from Service is in foreground (Active)

I can use ListActivity Intent but the problem is this brings up activity even when its in background.

I also considered using registerDataSetObserver on ListAdapter but that mandates that cursor should be updated. Updating the Cursor from external service may not be feasible.

Do we have a generic solution to this ?

解决方案

Do we have a generic solution to this ?

Probably a dozen of them. Here are a few:

  • Have the activity register a listener object with the service in onResume() and remove it in onPause()
  • Send a private broadcast, picked up by the activity via registerReceiver() when it is in the foreground
  • Have the activity supply a "pending result"-style PendingIntent to the service
  • Use a ResultReceiver
  • Use a ContentProvider, with the activity holding onto a Cursor from the provider, and the service updating the provider

This set of projects demonstrates the first three, in the context of remote services.

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

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