Search code examples
javaandroidobjectencapsulationpojo

Android Storing Values


I apologize in advance, this might sound like an incredibly dumb question. I am a bit out of it today. So I am finishing up a Login Verification activity that uses a REST API to authenticate. It works just fine, but I would like on success to save that email in an object so that the rest of the application knows the email of the user currently in the app. I made a POJO class called AccountInformation that will hold this email (among other details later on), but I am drawing a blank as to how I can access those values outside of the class.

For example, I have to make a call in the Account Modification class that requires me to send the email in a request. But the email was stored in an object I made in a separate activity. I am so sorry if I'm not making sense, but I really feel like an idiot right now because this should be simple.


Solution

  • You should store it in something persistent like SharedPreferences. When the app goes into the background, the whole process could be destroyed without warning. When you return to the app, the fields of your POJO will be uninitialized, or the reference to the POJO itself will be null, depending now it's initialized.

    Yes, this should be simple. The entire Android framework is extraordinarily and unnecessarily complicated.