Pavel
Pavel

Reputation: 5353

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 similar 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!

Upvotes: 1

Views: 1951

Answers (3)

m6tt
m6tt

Reputation: 4223

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

Upvotes: 1

Francesco Laurita
Francesco Laurita

Reputation: 23552

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.

Upvotes: 1

kgiannakakis
kgiannakakis

Reputation: 104188

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().

Upvotes: 0

Related Questions