Join Chiu-Ki Chan for an in-depth discussion in this video SharedPreferencesFavorites, part of Effective Android Testing for Mobile Developers.
- [Instructor] To start a favorites,…we are going to use shared preferences.…Go to the Java folder,…right-click on data local,…new Java class.…Call it shared preferences favorites.…Create a private final share preferences field.…It is not initialized yet,…so press Alt+Enter and say…initialize in constructor.…
Accept the default value of null for now.…To initialize it, we will need a context,…so we'll edit as a perimeter…to the constructor in line eight,…context context.…Then, go to the next line and replace null…with context.getSharedPreferences.…We'll give it the file name favorites.xml.…And then, we are going to call the mode…context.MODE_PRIVATE,…meaning that we do not want other apps…to have access to it.…
For favorites we will need three operations.…Get, to retrieve what is previously stored,…put, to stall a new value,…and then we'll have a convenience method toggle,…which retrieves the old value,…flip it from true to false or false to true,…and then put it inside the stall…and then return the value so that we can display it.…
- Why test?
- Local vs. on-device
- Code coverage
- UI testing
- Hermetic environment
- Dependency injection
- Testing with MVP
Skill Level Intermediate
Android App Development: Unit Testingwith James P White2h 58m Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
1. Testing Considerations
2. Test as You Go
3. UI Testing
4. Hermetic Environment
5. Robot Pattern
- 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.