Udacity / Google Developing Android Apps Cheat Sheet: by Via
Udacity / Google Developing Android Apps Cheat Sheet: by Via
Loaders
To create a loader:
1) Auto-import the Loader class as you type, Then, have the IDE fill
in the Loader Callbacks for you:
LoaderManager.LoaderCallbacks<String>{
onCreateLoader()
onLoadFinished()
onLoaderReset()
}
2) Create an integer constant for a loader ID:
Preferences
Layout Manager > RECYCLER VIEW < View Holder < Adapter < There are 5 different ways to persist data:
Data 1) "Saved Instance State" uses key-value pairs (a map) to save the
"Whereas the View Holder determines how an individual entry is state of one of your views. It's usually used to save state when the
displayed, the Layout Manager determines how the entire collection view must be quickly destroyed and restarted such as when the
of entries is displayed." phone is rotated or if the activity has to be destroyed because of
"Layout Manager is a key part of the way recycling works in Recycler memory constraints but will need to be recreated at some point,
View since it determines when to recycle views that are no longer when it returns to the foreground. If the user quits the app or restarts
visible to the user." the phone, this data is lost.
If you need to have data persist beyond app closures and phone
RecyclerView Adapter: restarts, it needs to be saved to a file system.
An adaper is called by Recycler View to: 2) The SharedPreferences class saves simple key-value pairs (a
map) to a file. Keys are always strings. values are primitives (as
Create new items in the form of ViewHolders
opposed to objects). This can be used for things like saving a String
Populate (or bind) items with data
for the user name between sessions or the URL (as a String) of the
Return information abou the data (IE # of items) last web page someone was on and returning to it when restarting
The Adapter requires 3 functions to be overridden: the app.
OnCreateViewHolder() : Called when RecyclerView instantiates a 3) For more complex data (IE: an object) we use a database, and
new ViewHolder instance (inflates from XML or generates it in code) Android uses SQL lite. Android also has various framework
OnBindViewHolder() : Called when RecyclerView wants to populate components (such as Content Providers) that allow you to manage
ViewHolder with data and share data in databases.
GetItemCount() : Returns the number of items in teh data source. 4) For larger items (IE: audio, video, image or e-book files) you can
(This might be called a number of times during the layout process so save to internal or external storage.
it needs to be a fast, efficient process.) 5) We can also save larger files to a Cloud or Firebase, rather than
taking up space in the device's storage.
Recycler View Layout Manager