-3

I am curious about sharedPreferences and my real question is Variable stored using sharedPreferences in one activity can be fetched in second activity but can i get the value of variable again in third activity ? does it provide this usage? if not How can i achieve this task?

Zulqurnain Jutt
  • 1,083
  • 3
  • 15
  • 41
  • couldn't you get it in the third activity the same way you get it in the second activity? Could you edit your question to provide some code that you tried? – Bill Aug 02 '16 at 19:50
  • Did you try? The way the question is phrased right now, there is no reason you couldn't get the value of the variable anywhere in your application. – Magnus Aug 02 '16 at 19:55
  • wow , first it was conceptual question , not a coding questions that's why there is no example , – Zulqurnain Jutt Aug 02 '16 at 21:16

2 Answers2

0

Mr. Z,

You can store a static reference of SharedPreferences in the activity it corresponds to (when the activity's onCreate is called, instantiate the reference). Otherwise, the only thing I can think of for globally retrieving data in a program is just reading files from the scard storage that you create.

If something is unclear or incomplete, please comment and I'll try to help!

Adam Ratzman
  • 143
  • 2
  • 8
0

You can use it as many times you wish, unless you explicitly clear it by code or your app's local data is removed (like when uinstalling or clearing local storage).

Be aware that SharedPreferences should not be used to store important information as it might get lost occasionally.

Community
  • 1
  • 1