When you need to share data among multiple app components, you can store the data in persistent storage. But if you only need to keep data for a particular session, a singleton class can be a simple and elegant solution.
- [Instructor] Mobile application developers in general…and Android developers in particular,…have to pay a lot of attention to state management.…Holding on to data when the device orientation changes…or other things change that can make you lose…references to objects.…I'm going to show you a very simple technique…that makes data persistence a lot easier.…It let's you persist data not just…through configuration changes,…but also sharing that data among different activities…and services and other components of your application.…
I'm going to use a simple Java singleton class.…A class for which there's only one possible instance.…Now, you'll see similar recommendations…using something called the application context.…In Android the application context is a singleton,…but for data persistence it's no better or worse…than just a simple singleton you can create yourself.…Right now in this application,…I'm collecting a bit of information from the user…with a dialogue.…And then, I'm saving it to a field that I've called name.…
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.