Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends.

Similar presentations


Presentation on theme: "Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends."— Presentation transcript:

1 Mobile Application Development Data Storage

2 Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires.

3 Your data storage options are the following: Shared PreferencesStore private primitive data in key-value pairs. Internal Storage Store private data on the device memory. External Storage store public data on the shared external storage. SQLLite databasesStore structured data in a private database. Network ConnectionStore data on the web with your own network server.

4 What is preferences Shared preferences are simply sets of data values that are stored persistently. By persistence, we are talking about data that persists across application lifecycle events. In other words, the application (or device, for that matter) can be started and stopped without losing the data. The next time the user launches the application, that data will still be available. An individual preference is simply a key-value pair with a specific data type for the value. The preference key is simply a string that uniquely identifies the preference and the value is just that: the value of that preference.

5 For example, your application might want to store the user’s name. The application could have a single preference to store this information: The data type of the preference could be a String The key could be a string called “UserName” The value would be the actual username string, such as “AndroidPowerUser123” or “NASR”

6 A preference can be any of a number of different data types. The following data types are supported by the SharedPreferences class:  Boolean values  Float values  Integer values  Long values  String values

7 How shared Preference work a game application might have a set of preferences for user information (user name, email, high score, etc.) and a set of preferences for game state (current level, current score, etc.). Preferences can be stored at the activity or application level. Application-level preferences are available across all activities. These preferences are retrieved using the application Context class method called getSharedPreferences() by name. For example:

8 How shared Preference work Import android.content.sharedPreferences;

9 Preferences Preferences are user-specific settings for an application. Preferences usually consist of some configuration data as well as a user interface to manipulate that data

10 Preferences From user interface point of view preferences can be simple text values, checkboxes, selections from a pull-down menu, or similar. From data point of view, preferences is a collection of name-value pairs, also known as key-value or attribute-value pairs. The values are basic data types, such as integers, Booleans, strings, and similar

11 preferences is the root element that defines our main preference screen. It has three children, all. This is simply a piece of editable text. Other common elements here could be,, and so on.

12 Android System Resources To refer to Android system resources prefix them with with android:keyword in XML, for example @android:drawable/ic_menu_preferenc es. If you are referring to an Android system resource from Java, then you use android.R instead the usual R reference. The actual resource files are in your SDK, inside specific platform folder. For example, if you are using Android 9 (Gingerbread), the location of the resource folder would be android- sdk/platforms/android-9/data/res/.

13 Shared Preferences class this class is called SharedPreference refers to the fact that this preference is easily accessible from anywhere in this application. So, any component of an Android application, such as Activities, Services, Broadcast Receivers, and Content Providers.


Download ppt "Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends."

Similar presentations


Ads by Google