Saving Data on Android (raywenderlich Tutorial Team etc.) (Z-Library)

Author: raywenderlich Tutorial Team, Aldo Olivares Dominguez, Jennifer Bailey, Dean Djermanović

技术

No Description

📄 File Format: PDF
💾 File Size: 19.3 MB
57
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
(This page has no text content)
📄 Page 2
Saving Data on Android Jennifer Bailey, Aldo Olivares Dominguez & Dean Djermanović Copyright ©2019 Razeware LLC. No/ce of Rights All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner. No/ce of Liability This book and all corresponding materials (such as source code) are provided on an “as is” basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software. Trademarks All trademarks and registered trademarks appearing in this book are the property of their own respective owners. Saving Data on Android raywenderlich.com 2
📄 Page 3
About the Authors Jennifer Bailey is an author of this book. She is a full-time professor at Aims Community College for the past 8 years. She teaches computer science courses utilizing Java, C++ and Python as well as applied certificates in Android Development, iOS Development and C#. Prior to teaching, she was a C# developer in the financial industry for 7 years. Jenn is a hobbyist developer in many platforms, specializing most in Android and loves to learn new things and share her knowledge with others. When she's not at the computer or presenting and teaching a new technology, she enjoys spending time with her teenage daughter enjoying the outdoors in beautiful Colorado. Aldo Olivares Dominguez is an author of this book. He is a software engineer at Oracle where he has been creating web services and software applications for clients around the world for more than four years. He has also been developing Android Applications as a freelancer for more than seven years and is the author of many courses and tutorials about Android Development on platforms such as Udemy and Raywenderlich.com Dean Djermanović is an author of this book. He's an experienced Android developer from Croatia working at Five Agency where he works on Rosetta Stone app for learning languages which has over 5 million downloads and almost 500 000 monthly active users. Previously, he's been a part of two other mobile development agencies in Croatia where he worked on many smaller custom mobile solutions for various industries. Very passionate about Android, software development, and technology in general with a particular interest in software architecture. He is always trying to learn more, exchange knowledge with others, improve in every aspect of life, and become the best version of himself. Saving Data on Android raywenderlich.com 3
📄 Page 4
About the Editors Filip Babic is a technical editor of this book. He is an experienced Android developer from Croatia, working at the Five Agency, building world-known applications, such as the RosettaStone language-learning application and AccuWeather, the globally known weather reporting app. He's also a Google Developer Expert for Android, trying to give back to the community everything he's learned over the years. Previously he worked at COBE d.o.o., a German-owned mobile agency, which is partners with the biggest German media company. He's enthusiastic about the Android ecosystem, focusing extensively on applying Kotlin to Android applications, and building scalable, testable and user-friendly applications. Faud Kamal is a technical editor of this book. He provides mobile strategy, architecture & development for the Health & Fitness markets. If you’ve ever been to an airport, you’ve likely seen his work - the flight arrival and departure screens are a Flash 7 interface he wrote towards the beginning of the millennium. He can be contacted through anaara.com. Massimo Carli is the final pass editor of this book. Massimo has been working with Java since 1995 when he co-founded the first Italian magazine about this technology http://www.mokabyte.it. After many years creating Java desktop and enterprise application, he started to work in the mobile world. In 2001 he wrote his first book about J2ME. After many J2ME and Blackberry applications, Massimo then started to work with Android in 2008. The same year he wrote the first Italian book about Android, a best seller on Amazon.it. That was the first of a series of 10 books about Android and Kotlin. Massimo worked at Yahoo and Facebook and he's actually Senior Mobile Engineer at Spotify. He's a musical theatre lover and a supporter of the soccer team S.P.A.L. Saving Data on Android raywenderlich.com 4
📄 Page 5
About the Ar/st Vicki Wenderlich is the designer and artist of the cover of this book. She is Ray’s wife and business partner. She is a digital artist who creates illustrations, game art and a lot of other art or design work for the tutorials and books on raywenderlich.com. When she’s not making art, she loves hiking, a good glass of wine and attempting to create the perfect cheese plate. Saving Data on Android raywenderlich.com 5
📄 Page 6
Table of Contents: Overview Book License 13................................................................................... Who This Book Is For 14.................................................................... What You Need 15.............................................................................. Book Source Code & Forums 16...................................................... About the Cover 18............................................................................. Sec/on 1: Saving Data Using Android SDK 19.............. Chapter 1: Using Files 20........................................................ Chapter 2: Shared Preferences 41......................................... Chapter 3: SQLite Database 49............................................. Chapter 4: ContentProvider 72.............................................. Sec/on 2: Using Room 91................................................... Chapter 5: Room Architecture 92.......................................... Chapter 6: EnVty DefiniVons 104......................................... Chapter 7: Mastering RelaVons 119..................................... Chapter 8: The DAO PaZern 131.......................................... Chapter 9: Using Room with Google's Architecture Components 148....................................................................... Chapter 10: MigraVons with Room 171.............................. Sec/on 3: Using Firebase 187............................................ Chapter 11: Firebase Overview 189..................................... Chapter 12: IntroducVon to Firebase RealVme Database 199............................................................................. Saving Data on Android raywenderlich.com 6
📄 Page 7
Chapter 13: Reading to & WriVng from RealVme Database 214............................................................................. Chapter 14: RealVme Database Offline CapabiliVes 232 Chapter 15: Usage & Performance 238............................... Chapter 16: IntroducVon to Cloud Firestore 244.............. Chapter 17: Managing Data with Cloud Firestore 250.... Chapter 18: Reading Data from Cloud Firestore 260....... Chapter 19: Securing Data in Cloud Firestore 274........... Chapter 20: Cloud Storage 280............................................. Conclusion 289..................................................................................... Saving Data on Android raywenderlich.com 7
📄 Page 8
Table of Contents: Extended Book License 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Who This Book Is For 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What You Need 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Book Source Code & Forums 16. . . . . . . . . . . . . . . . . . . . . . . . . . About the Cover 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sec/on 1: Saving Data Using Android SDK 19. . . . . . . Chapter 1: Using Files 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reading and wriVng files in Android 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 21. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing the files in Device File Explorer 24. . . . . . . . . . . . . . . . . . . . . . . . Securing user data with a password 32. . . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding ParcelizaVon and SerializaVon 38. . . . . . . . . . . . . . . . . . . Key points 39. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 40. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 2: Shared Preferences 41. . . . . . . . . . . . . . . . . . . . . . . . . Understanding SharedPreferences 41. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng a reference to the SharedPreferences file 42. . . . . . . . . . . . . . . . Ge_ng started 43. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving the user preferences 44. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reading the user preferences 45. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reading and wriVng the prefs from MainAcVvity 46. . . . . . . . . . . . . . . . . Key points 47. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 48. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3: SQLite Database 49. . . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 51. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the SQLiteOpenHelper class 53. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving Data on Android raywenderlich.com 8
📄 Page 9
Reading from a database 60. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UpdaVng a TODO 62. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DeleVng a TODO 64. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unit TesVng with Robolectric 64. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 70. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 71. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 4: ContentProvider 72. . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding content provider basics 72. . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng Started 77. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ImplemenVng the methods in the content provider 81. . . . . . . . . . . . . . Challenge: CreaVng a client 87. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key Points 89. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here 89. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sec/on 2: Using Room 91. . . . . . . . . . . . . . . . . . . . . . . . . Chapter 5: Room Architecture 92. . . . . . . . . . . . . . . . . . . . . . . . . Object RelaVonal Mappers 93. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Room and Google's architecture components 94. . . . . . . . . . . . . . . . . . . Room advantages and concerns 100. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frequently asked Room quesVons 100. . . . . . . . . . . . . . . . . . . . . . . . . . . . Your app 101. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 102. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 6: EnVty DefiniVons 104. . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 105. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tables and enVVes 106. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CreaVng your enVVes 111. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 117. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 118. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 7: Mastering RelaVons 119. . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 120. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving Data on Android raywenderlich.com 9
📄 Page 10
RelaVons and enVty-relaVonship diagrams 121. . . . . . . . . . . . . . . . . . . . . CreaVng your relaVons 125. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 130. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 8: The DAO PaZern 131. . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 132. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using DAOs to query your data 133. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CreaVng a provider class 137. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TesVng your database 140. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 146. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 147. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 9: Using Room with Google's Architecture Components 148. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 149. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using LiveData with a repository 150. . . . . . . . . . . . . . . . . . . . . . . . . . . . . CreaVng ViewModels 155. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Defining your Views 162. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 169. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 170. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 10: MigraVons with Room 171. . . . . . . . . . . . . . . . . . . . Ge_ng started 172. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . MigraVons 173. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding Room migraVons 173. . . . . . . . . . . . . . . . . . . . . . . . . . . . . CreaVng Room migraVons 174. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 186. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 186. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sec/on 3: Using Firebase 187. . . . . . . . . . . . . . . . . . . . . . Chapter 11: Firebase Overview 189. . . . . . . . . . . . . . . . . . . . . . . Firebase history 189. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Why Firebase? 190. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving Data on Android raywenderlich.com 10
📄 Page 11
Ge_ng started 191. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 198. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 198. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 12: IntroducVon to Firebase RealVme Database 199. Overview 200. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Se_ng up RealVme Database 201. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data structure 211. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 213. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 213. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 13: Reading to & WriVng from RealVme Database 214. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reading and wriVng data 215. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 230. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 230. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 14: RealVme Database Offline CapabiliVes 232. . . . . . Enabling disk persistence 233. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other offline scenarios and network connecVvity features 235. . . . . . . Key points 237. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 237. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 15: Usage & Performance 238. . . . . . . . . . . . . . . . . . . . Pricing model 238. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LimitaVons 239. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Performance 240. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 242. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 243. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 16: IntroducVon to Cloud Firestore 244. . . . . . . . . . . . What is Cloud Firestore? 244. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cloud Firestore vs. RealVme database 245. . . . . . . . . . . . . . . . . . . . . . . . . Cloud Firestore data structure 246. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 248. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving Data on Android raywenderlich.com 11
📄 Page 12
Where to go from here? 249. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 17: Managing Data with Cloud Firestore 250. . . . . . . . Ge_ng started 250. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . WriVng data 253. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UpdaVng data 256. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DeleVng data 257. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Firebase console 257. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 258. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 259. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 18: Reading Data from Cloud Firestore 260. . . . . . . . . Reading data 261. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Performing queries 264. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working offline 271. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other features 271. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 272. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 273. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 19: Securing Data in Cloud Firestore 274. . . . . . . . . . . What are security rules? 274. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 275. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding security rules 277. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 278. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 279. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 20: Cloud Storage 280. . . . . . . . . . . . . . . . . . . . . . . . . . . Cloud Storage overview 281. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ge_ng started 282. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IntegraVng Cloud Storage with your app 284. . . . . . . . . . . . . . . . . . . . . . . Key points 288. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 288. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conclusion 289. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving Data on Android raywenderlich.com 12
📄 Page 13
LBook License By purchasing Saving Data on Android, you have the following license: • You are allowed to use and/or modify the source code in Saving Data on Android in as many apps as you want, with no attribution required. • You are allowed to use and/or modify all art, images and designs that are included in Saving Data on Android in as many apps as you want, but must include this attribution line somewhere inside your app: “Artwork/images/designs: from _Saving Data on Android, available at www.raywenderlich.com”. • The source code included in Saving Data on Android is for your personal use only. You are NOT allowed to distribute or sell the source code in Saving Data on Android without prior authorization. • This book is for your personal use only. You are NOT allowed to sell this book without prior authorization, or distribute it to friends, coworkers or students; they would need to purchase their own copies. All materials provided with this book are provided on an “as is” basis, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. All trademarks and registered trademarks appearing in this guide are the properties of their respective owners. raywenderlich.com 13
📄 Page 14
WWho This Book Is For This book is for developers who are comfortable with Kotlin and want to implement the proper solution when managing persistence, local or remote, in Android applications. If you’re looking for more background on the Kotlin language, we recommend our book, Kotlin Apprentice, which goes into depth on the Kotlin language itself: • https://store.raywenderlich.com/products/kotlin-apprentice If you want to learn more about Android app development in Kotlin, we recommend working through our classic book, Kotlin Apprentice: • https://store.raywenderlich.com/products/kotlin-apprentice raywenderlich.com 14
📄 Page 15
WWhat You Need To follow along with this book, you need: • IntelliJ IDEA Community Edition 2019.1.x: Available at https:// www.jetbrains.com/idea/. This is the environment in which you’ll develop most of the sample code in this book. • Kotlin playground: You can also use the Kotlin Playground available at the Kotlin home page at https://play.kotlinlang.org. • Android Studio 3.x: Available at https://developer.android.com/studio/. This is the environment in which you’ll develop most of the sample code in this book. raywenderlich.com 15
📄 Page 16
BBook Source Code & Forums If you bought the digital edi/on The digital edition of this book comes with the source code for the starter and completed projects for each chapter. These resources are included with the digital edition you downloaded from store.raywenderlich.com. If you bought the print version You can get the source code for the print edition of the book here: https://store.raywenderlich.com/products/saving-data-on-android Forums We’ve also set up an official forum for the book at forums.raywenderlich.com. This is a great place to ask questions about the book or to submit any errors you may find. Digital book edi/ons We have a digital edition of this book available in both ePUB and PDF, which can be handy if you want a soft copy to take with you, or you want to quickly search for a specific term within the book. Buying the digital edition version of the book also has a few extra benefits: free updates each time we update the book, access to older versions of the book, and you can download the digital editions from anywhere, at anytime. raywenderlich.com 16
📄 Page 17
Visit our Saving Data on Android store page here: • https://store.raywenderlich.com/products/saving-data-on-android. And if you purchased the print version of this book, you’re eligible to upgrade to the digital editions at a significant discount! Simply email support@razeware.com with your receipt for the physical copy and we’ll get you set up with the discounted digital edition version of the book. Saving Data on Android Book Source Code & Forums raywenderlich.com 17
📄 Page 18
AAbout the Cover Dragons are an extremely common and ancient piece of folklore in nearly all cultures around the world. Most dragons are thought to breathe fire, or even ice, but legend has it that green dragons breathe acid. Any warrior brave enough to charge a green dragon would have the story of her battle permanently etched on her armor and shield from the dragon’s acid. Saving data on Android etches the story of data in a persistent manner on the user’s device. There’s hardly an app out there that doesn’t persist data in some way. After reading Saving Data on Android, you’ll be armed and ready to charge fearlessly into battle with the dragons of development, to save your users’ data! raywenderlich.com 18
📄 Page 19
Sec/on 1: Saving Data Using Android SDK Managing persistence is one of the main features that every mobile environment should provide, and Android is no different. In this chapter, you'll learn, through practical examples, how to use the API that Android SDK provides to persist data. You'll learn when and how to manage persistence depending on the type and quantity of data. • Chapter 1: Using Files: Android contains most of the API of Java and so the abstractions into the java.io package which allow you to deal with Files. In this chapter, you'll learn how to create, write, update and delete data into files. Here you'll have the opportunity to manage security using encryption and permissions. • Chapter 2: Using SharedPreferences: SharedPreferences are useful if you need to persist a small quantity of data like texts or a set of values of primitive types. In this chapter, you'll learn how to persist and recover a small quantity of data. • Chapter 3: SQLite Database: Android also provides SQLite as a small and powerful DataBase Management System. In this chapter, you'll learn how to create a DB with SQLite and how to execute queries. You'll also learn how to manage the lifecycle of a DB from the creation to the upgrade or downgrade of versions. • Chapter 4: Content Provider: Android also provides an abstraction on top of a DB SQLite or memory, that allows different applications to communicate and share information safely and securely. You can do this using ContentProvide which is one standard component of Android. In this chapter, you'll learn how to create a ContentProvider and how to use it to make applications to communicate. raywenderlich.com 19
📄 Page 20
1Chapter 1: Using Files By Jennifer Bailey There are many ways to store data in an Android app. One of the most basic ways is to use files. Similar to other platforms, Android uses a disk-based file system that you can leverage programmatically using the File API. In this chapter, you’ll learn how to use files to persist and retrieve information. Reading and wri/ng files in Android Android separates the available storage into two parts, internal and external. These names reflect an earlier time when most devices offered built-in, non-volatile memory (internal storage) and/or a removable storage option like a Micro SD card (external storage). Nowadays, many devices partition the built-in, permanent storage into separate partitions, one for internal and one for external. It should be noted that external storage does not indicate or guarantee that the storage is removable. There are a few functional differences between internal and external storage: • Availability: Internal storage is always available. External storage, on the other hand, is not. Some devices will let you mount external storage using a USB connection or other option; this generally makes it removable. • Accessibility: By default, files stored using the internal storage are only accessible by the app that stored them. Files stored on the external storage system are usually accessible by everything — however, you can make files private. raywenderlich.com 20
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List