如何保持和访问数据广播接收器? [英] How to keep and access data in BroadcastReceiver?

查看:107
本文介绍了如何保持和访问数据广播接收器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我理解的Andr​​oid手册,广播接收器被视为无状态的实体,所以我应该保持一个服务将作为数据容器(这些都是我的结论)。

根据数据访问的每一个请求,我应该执行 startService (?) - ?我可以用这种方式传递数据服务,但如何找回数据

我的意思是在推荐的方式?我能想到通过走出去的数据,并在完成服务将改变它,所以当 startService 的回报,我可以检查数据我送,以便检索结果。


解决方案

  

如果我理解的Andr​​oid手册,广播接收器被视为无状态的实体,所以我应该保持一个服务将作为数据容器(这些都是我的结论)。


有一个服务完全围绕守住数据将让你的用户不喜欢你,不能保证该数据无论如何都会坚持。用户和操作系统可以每当他们希望,将摆脱你的过程。

请持有该过程需要调用之间的生存数据使用的文件(例如,数据库,共享preferences )。

If I understand Android manual, BroadcastReceiver is treated as stateless entity, so I should keep a service which will serve as data container (those are my conclusions).

As per each request for data access I should execute startService (?) -- I can pass this way data to service, but how to get data back?

I mean in recommended way? I could think of passing "out" data, and service on completion would change it, so when startService returns I could check the data I sent in order to retrieve the result.

解决方案

If I understand Android manual, BroadcastReceiver is treated as stateless entity, so I should keep a service which will serve as data container (those are my conclusions).

Having a service around solely to hold onto data will make your users dislike you, and is no guarantee that the data will stick around anyway. The user and the OS can and will get rid of your process whenever they wish.

Please use files (e.g., database, SharedPreferences) for holding data that needs to survive between process invocations.

这篇关于如何保持和访问数据广播接收器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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