Unit 3
Unit 3
• Android provides many ways of storing data of an • Shared – distribute data • Activity preference : getPreferences (int mode)
application. One of this way is called Shared • Preference – important or preferable • developer have to call function getPreferences(int
Preferences API. • Preference File mode)
UNIT III: DATA • Eg:- Username, Password, Firstname, Lastname,
email id, mobile no, DOB, etc..(profile details)
• Preference file is XML file saved in internal memory in
device.
• Use this if you need to use only one shared preference
file for the activity.
Managing data using Managing data using Managing data using Managing data using
SQLite database SQLite database SQLite database SQLite database
• Put information into a database • Delete information from a database • Update a database • Saving data to a database is ideal for repeating or
• Insert data into the database by passing • To delete rows from a table, you need to provide • When you need to modify a subset of your database structured data, such as contact information.
a ContentValues object to the insert() method: selection criteria that identify the rows to values, use the update() method. • The APIs you'll need to use a database on Android are
• SQLiteDatabase db=mDbHelper.getWritableDatabase(); the delete() method. • Updating the table combines the ContentValues syntax available in the android.database.sqlite package.
• Read information from a database of insert() with the WHERE syntax of delete().
• To read from a database, use the query() method, • SQLiteDatabase db=mDbHelper.getWritableDatabase();
passing it your selection criteria and desired
columns. The method combines elements
of insert() and update()
• SQLiteDatabase db=mDbHelper.getReadableDatabase();
Android in build
Content providers Content providers Content providers
content providers
• Sharing access to your application data with other • A content provider manages access to a central • Accessing a provider • One of the built-in providers in the Android platform
applications repository of data. • When you want to access data in a content provider, is the user dictionary, which stores the spellings of
• Sending data to a widget • A provider is part of an Android application, which you use the ContentResolver object in your non-standard words that the user wants to keep.
• Returning custom search suggestions for your often provides its own UI for working with the data. application's Context to communicate with the
application through the search framework • A content provider presents data to external provider as a client.
using SearchRecentSuggestionsProvider. applications as one or more tables that are similar to • The ContentResolver methods provide the basic
• Synchronizing application data with your server using the tables found in a relational database. "CRUD" (create, retrieve, update, and delete)
an implementation of AbstractThreadedSyncAdapter • A content provider coordinates access to the data functions of persistent storage.
• Loading data in your UI using a CursorLoader storage layer in your application for a number of •A common pattern for accessing
different APIs. a ContentProvider from your UI uses
a CursorLoader to run an asynchronous query in the
background.