4.3.5. SharedPreferences

You can have one or more files containing key–value pairs associated with each app—each key enables you to quickly look up a corresponding value. We use this capability to manipulate a file called searches in which we store the pairs of tags (the keys) and Twitter search queries (the values) that the user creates. To read the key–value pairs from this file we’ll use SharedPreferences objects (package android.content). To modify the file’s contents, we’ll use SharedPreferences.Editor objects (package android.content). The keys in the file must be Strings, and the values can be Strings or primitive-type values.

This app reads the saved searches in the Activity’s onCreate method—this is acceptable only because the amount of data being loaded is small. When an app is launched, Android creates a main thread called the UI thread which handles all of the GUI interactions. All GUI processing must be performed in this thread. Extensive input/output operations, such as loading data from files and databases should not be performed on the UI thread, because such operations can affect your app’s responsiveness. We’ll show how to perform I/O in separate threads in later chapters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.49.252