开发者

Storing variables for app access

I'm kinda noob to android so please bear with me. I'm currently developing app which uses tabs. My question now is: how to store values of variables so I can access them on the other tabs? I want to create something simila开发者_C百科r to sessions in PHP where I can save variables on one page and access on the other. Please can someone help me with this? There has to be an easy way to solve this. Thanks in advance!


There are several ways for doing this. The choise depends on the type of the data which you need to pass between Activities.

Here there is an overview about the different approachs.


Might be worth having a look at SharedPreferences:

How to use guide http://developer.android.com/guide/topics/data/data-storage.html#pref

Class ref http://developer.android.com/reference/android/content/SharedPreferences.html


One solution would be to use static variables to implement the "Singleton" pattern. This question presents a much better alternative for Android, which involves extending Application class and then accessing it using Context.getApplicationContext().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜