0

I want to save the ID of the user that I pass from PHP then I put it in a putExtra of an intent to move the string to my HomeActivity. To have a fast access, protected to see by the user and to access to in all activities, what do you recommend to use?

SOFe
  • 7,867
  • 4
  • 33
  • 61
Roger RV
  • 132
  • 3
  • 15
  • use [SharedPreferences](http://stackoverflow.com/questions/23024831/android-shared-preferences-example). – Akash Patel Dec 31 '16 at 09:37
  • @Roger RV i recommend you use shared preferences and clear them once user logs out – eLemEnt Dec 31 '16 at 09:37
  • If you use it really frequently, you may store it in an Application object. See also: http://stackoverflow.com/questions/4208886/using-the-android-application-class-to-persist-data – SOFe Dec 31 '16 at 09:41
  • @PEMapModder Thanks I'll see it and *SharedPreferences* – Roger RV Dec 31 '16 at 09:44
  • @RogerRV note that it is different from SharedPreferences. SharedPreferences is for storing data _in the harddisk (or SD card)_, while using an Application field is just a way to cache it in memory temporarily. If you want to use this method to keep a user always logged in in your app, you should use both, and a lazy-getter for your Application field. – SOFe Dec 31 '16 at 09:47

0 Answers0