- Android Wear Projects
- Ashok Kumar S
- 126字
- 2021-07-15 17:17:57
Fetching all the saved notes from SharedPreference
Fetching all the notes for this List type method needs a Context and then the SharedPreference reference using the PreferenceManager class. Then, we will create an instance of a List of notes for adding the notes after fetching it. We use the Map type for looping through the saved data inside SharedPreference. We will add all the data to the list inside the loop; it returns the noteList:
public static List<Note> getAllNotes(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); List<Note> noteList = new ArrayList<>(); Map<String, ?> key = sharedPreferences.getAll(); for (Map.Entry<String, ?> entry : key.entrySet()) { String savedValue = (String) entry.getValue(); if (savedValue != null) { Note note = new Note(entry.getKey(), savedValue); noteList.add(note); } } return noteList; }
推薦閱讀
- Mastering Concurrency in Go
- 基于差分進(jìn)化的優(yōu)化方法及應(yīng)用
- Visual C++應(yīng)用開發(fā)
- jQuery開發(fā)基礎(chǔ)教程
- 深入理解Elasticsearch(原書第3版)
- 區(qū)塊鏈技術(shù)與應(yīng)用
- C語言從入門到精通
- Learning Material Design
- 零基礎(chǔ)學(xué)C語言(升級版)
- ABAQUS6.14中文版有限元分析與實(shí)例詳解
- Building Microservices with Go
- Learning Dynamics NAV Patterns
- Spring MVC Cookbook
- 機(jī)器人ROS開發(fā)實(shí)踐
- Java EE框架開發(fā)技術(shù)與案例教程