You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28Lines changed: 28 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ Lessons learned from Android developers in [Futurice](http://www.futurice.com).
23
23
#### Use Robolectric for unit tests, Robotium for connected (UI) tests
24
24
#### Use Genymotion as your emulator
25
25
#### Always use ProGuard or DexGuard
26
+
#### Use SharedPreferences for simple persistence, otherwise ContentProviders
26
27
27
28
28
29
----------
@@ -520,6 +521,33 @@ Read more at [Proguard](http://proguard.sourceforge.net/#manual/examples.html) f
520
521
521
522
**DexGuard**. If you need hard-core tools for optimizing, and specially obfuscating release code, consider [DexGuard](http://www.saikoa.com/dexguard), a commercial software made by the same team that built ProGuard. It can also easily split Dex files to solve the 65k methods limitation.
522
523
524
+
### Data storage
525
+
526
+
527
+
#### SharedPreferences
528
+
529
+
If you only need to persist simple flags and your application runs in a single process SharedPreferences is probably enough for you. It is a good default option.
530
+
531
+
There are two reasons why you might not want to use SharedPreferences:
532
+
533
+
**Performance*: Your data is complex or there is a lot of it
534
+
**Multiple processes accessing the data*: You have widgets or remote services that run in their own processes and require synchronized data
535
+
536
+
537
+
#### ContentProviders
538
+
539
+
In the case SharedPreferences is not enough for you, you should use the platform standard ContentProviders, which are fast and process safe.
540
+
541
+
The single problem with ContentProviders is the amount of boilerplate code that is needed to set them up, as well as low quality tutorials. It is possible, however, to generate the ContentProvider by using a library such as [Schematic](https://github.com/SimonVT/schematic), which significantly reduces the effort.
542
+
543
+
You still need to write some parsing code yourself to read the data objects from the Sqlite columns and vice versa. It is possible to serialize the data objects, for instance with Gson, and only persist the resulting string. In this way you lose in performance but on the other hand you do not need to declare a column for all the fields of the data class.
544
+
545
+
546
+
#### Using an ORM
547
+
548
+
We generally do not recommend using an Object-Relation Mapping library unless you have unusually complex data and you have a dire need. They tend to be complex and require time to learn. If you decide to go with an ORM you should pay attention to whether or not it is _process safe_ if your application requires it, as many of the existing ORM solutions surprisingly are not.
549
+
550
+
523
551
### Thanks to
524
552
525
553
Antti Lammi, Joni Karppinen, Peter Tackage, Timo Tuominen, Vera Izrailit, Vihtori Mäntylä, Mark Voit, Andre Medeiros, Paul Houghton and other Futurice developers for sharing their knowledge on Android development.
0 commit comments