如何在多个活动之间共享相同的数据 [英] How to share same data between multiple activities
本文介绍了如何在多个活动之间共享相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个登录会话ID,多个活动需要使用该ID.如何在多个活动之间共享此公共数据?目前,我正在Intent中传递数据,但它无法正常工作.对于某些活动,我传递了一些其他数据,但通用数据丢失了.
I have a login session ID which multiple activities need to use. How do I share this common data between multiple activities? Presently, I'm passing the data in the Intent but it is not working properly. For some activities, I pass some other data, and the common data is lost.
推荐答案
一种方法是扩展Application
,然后在您的活动中调用getApplication
. 此网站包含一些示例.
One way to do it is to extend Application
, and then call getApplication
in your activities. This site has some examples.
这篇关于如何在多个活动之间共享相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文