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.
Building Android Apps with Cloud Serviceswith Albert Lo2h 37m Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
New This Week:
1. Android Development Tips Weekly
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.