SlideShare a Scribd company logo
Mobile Application Development
(ITEC-303)
Fahim Abid
fahim.abid@uettaxila.edu.pk
fahim.abid@uoc.edu.pk
Credits Hours 3(3,0)
Recommended Books
1. Professional Android application development, Reto Meier, Wrox Programmer to
Programmer, 2015.
2. Android Programming: The Big Nerd Ranch Guides, Phillips, B. & Hardy, B., 2nd
Edition, 2014.
3. iOS Programming: The Big Nerd Ranch Guide, Conway, J., Hillegass, A., & Keur, C.,
5th Edition, 2014.
Creating and Saving Preferences
To create or modify a Shared Preference, call getSharedPreferences on the
application Context, passing in the name of the Shared Preferences to change.
Shared Preferences are shared across an application’s components but aren’t
available to other applications.
Android provides many ways of storing data of an application. One of this way is
called Shared Preferences. Shared Preferences allow you to save and retrieve data in
the form of key, value pair.
Android provides the SharedPreferences object to help you save simple application
data. Using the SharedPreferences object, you can save the data you want through
the use of key/value pairs, specify a key for the data you want to save, and then both
it and its value will be saved automatically to an XML file.
In order to use shared preferences, you have to call a method
getSharedPreferences() that returns a SharedPreference instance pointing to the file
that contains the values of preferences.
To modify a Shared Preference, use the SharedPreferences.Editor class. Get the
Editor object by calling edit on the SharedPreferences object you want to change. To
save edits, call commit on the Editor, as shown in the code snippet below.
SharedPreferences sharedpreferences =
getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
Mobile Application Development-Lecture 13 & 14.pdf
Retrieving Shared Preferences
Accessing saved Shared Preferences is also done with the getSharedPreferences
method. Pass in the name of the Shared Preference you want to access, and use the
type-safe get<type> methods to extract saved values.
Each getter takes a key and a default value (used when no value is available for that
key), as shown in the skeleton code below:
Mobile Application Development-Lecture 13 & 14.pdf
Persisting Data to Files
Persistent data is data which you want to be available even after you fully close and
restart your app. The three most common ways to safe this data locally is by using
SharedPreferences, a local database or the file system (store data as a file).
Android supports the following ways of storing data in the local file system:
 Files - You can create and update files.
 Preferences - Android allows you to save and retrieve persistent key-value pairs of
primitive data type.
 SQLite database - instances of SQLite databases are also stored on the local file
system.
Creating and Using Databases
SQLite is a open source SQL database that stores data to a text file on a device.
Android comes in with built in SQLite database implementation. SQLite supports all
the relational database features.
Database - Package
The main package is android.database.sqlite that contains the classes to manage
your own databases.
Database - Creation
In order to create a database you just need to call this method
openOrCreateDatabase with your database name and mode as a parameter. It
returns an instance of SQLite database which you have to receive in your own
object. Its syntax is given below.
Database - Insertion
we can create table or insert data into table using execSQL method defined in
SQLiteDatabase class. Its syntax is given below:
Database - Fetching
We can retrieve anything from database using an object of the Cursor class. We will
call a method of this class called rawQuery and it will return a resultset with the
cursor pointing to the table. We can move the cursor forward and retrieve the data.
Database - Helper class
For managing all the operations related to the database , an helper class has been
given and is called SQLiteOpenHelper. It automatically manages the creation and
update of the database. Its syntax is given below:
public class DBHelper extends SQLiteOpenHelper {
public DBHelper() {
super(context,DATABASE_NAME,null,1);
}
public void onCreate(SQLiteDatabase db) {}
public void onUpgrade(SQLiteDatabase database, int
oldVersion, int newVersion) {}
}

More Related Content

PPTX
Mobile application Development-UNIT-V (1).pptx
DOCX
Android-data storage in android-chapter21
PDF
Mobile Application Development -Lecture 11 & 12.pdf
PPTX
Android session 4-behestee
PPTX
12_Data_Storage_Part_2.pptx
PPT
Data Storage In Android
PDF
Android - Saving data
PPT
"Android" mobilių programėlių kūrimo įvadas #3
Mobile application Development-UNIT-V (1).pptx
Android-data storage in android-chapter21
Mobile Application Development -Lecture 11 & 12.pdf
Android session 4-behestee
12_Data_Storage_Part_2.pptx
Data Storage In Android
Android - Saving data
"Android" mobilių programėlių kūrimo įvadas #3

Similar to Mobile Application Development-Lecture 13 & 14.pdf (20)

PPTX
Mobile Application Development (Shared Preferences) class-06
PPTX
Android Training (Storing & Shared Preferences)
PDF
Lab4 - android
PPTX
Share preference
PDF
Android datastorage
PPT
Android booting sequece and setup and debugging
PPTX
Android Application Components-BroadcastReceiver_Content Provider.pptx
PPTX
MobileApplicationDevelopment SQLite.pptx
PPTX
SHARED PREFERENCES IN ANDROID APPS.pptx
PPTX
SHARED PREFERENCES IN ANDROID APPS.pptx
PPTX
6CS027 Lecture 5 Files and Database Storage (1).pptx
PDF
Mobile Application Development -Lecture 09 & 10.pdf
PDF
Comprehensive Guide to Effective Introduction to Database Systems Principles
PPTX
Fundamentals of Database system - Databases and Database Users
PPT
Unit 2 in environment science and technology
PDF
Android App Development 05 : Saving Data
DOCX
Software Systems Modularization
PPT
eyeryeryeryeryeyeyeryeryyerye13872085.ppt
PPTX
Tk2323 lecture 7 data storage
ODP
Case Study FourSquare and Facebook Search Mobile Application
Mobile Application Development (Shared Preferences) class-06
Android Training (Storing & Shared Preferences)
Lab4 - android
Share preference
Android datastorage
Android booting sequece and setup and debugging
Android Application Components-BroadcastReceiver_Content Provider.pptx
MobileApplicationDevelopment SQLite.pptx
SHARED PREFERENCES IN ANDROID APPS.pptx
SHARED PREFERENCES IN ANDROID APPS.pptx
6CS027 Lecture 5 Files and Database Storage (1).pptx
Mobile Application Development -Lecture 09 & 10.pdf
Comprehensive Guide to Effective Introduction to Database Systems Principles
Fundamentals of Database system - Databases and Database Users
Unit 2 in environment science and technology
Android App Development 05 : Saving Data
Software Systems Modularization
eyeryeryeryeryeyeyeryeryyerye13872085.ppt
Tk2323 lecture 7 data storage
Case Study FourSquare and Facebook Search Mobile Application
Ad

More from AbdullahMunir32 (18)

PDF
Mobile Application Development-Lecture 15 & 16.pdf
PDF
Mobile Application Development -Lecture 07 & 08.pdf
PDF
Mobile Application Development Lecture 05 & 06.pdf
PDF
Mobile Application Development-Lecture 03 & 04.pdf
PDF
Mobile Application Development-Lecture 01 & 02.pdf
PDF
Parallel and Distributed Computing Chapter 13
PDF
Parallel and Distributed Computing Chapter 12
PDF
Parallel and Distributed Computing Chapter 11
PDF
Parallel and Distributed Computing Chapter 10
PDF
Parallel and Distributed Computing Chapter 9
PDF
Parallel and Distributed Computing Chapter 8
PDF
Parallel and Distributed Computing Chapter 7
PDF
Parallel and Distributed Computing Chapter 6
PDF
Parallel and Distributed Computing Chapter 5
PDF
Parallel and Distributed Computing Chapter 4
PDF
Parallel and Distributed Computing chapter 3
PDF
Parallel and Distributed Computing Chapter 2
PDF
Parallel and Distributed Computing chapter 1
Mobile Application Development-Lecture 15 & 16.pdf
Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development Lecture 05 & 06.pdf
Mobile Application Development-Lecture 03 & 04.pdf
Mobile Application Development-Lecture 01 & 02.pdf
Parallel and Distributed Computing Chapter 13
Parallel and Distributed Computing Chapter 12
Parallel and Distributed Computing Chapter 11
Parallel and Distributed Computing Chapter 10
Parallel and Distributed Computing Chapter 9
Parallel and Distributed Computing Chapter 8
Parallel and Distributed Computing Chapter 7
Parallel and Distributed Computing Chapter 6
Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 4
Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing Chapter 2
Parallel and Distributed Computing chapter 1
Ad

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Lesson notes of climatology university.
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Institutional Correction lecture only . . .
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Pre independence Education in Inndia.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Insiders guide to clinical Medicine.pdf
Sports Quiz easy sports quiz sports quiz
VCE English Exam - Section C Student Revision Booklet
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Lesson notes of climatology university.
Basic Mud Logging Guide for educational purpose
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
TR - Agricultural Crops Production NC III.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Complications of Minimal Access Surgery at WLH
Pre independence Education in Inndia.pdf
Renaissance Architecture: A Journey from Faith to Humanism
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
Final Presentation General Medicine 03-08-2024.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Insiders guide to clinical Medicine.pdf

Mobile Application Development-Lecture 13 & 14.pdf

  • 1. Mobile Application Development (ITEC-303) Fahim Abid fahim.abid@uettaxila.edu.pk fahim.abid@uoc.edu.pk
  • 2. Credits Hours 3(3,0) Recommended Books 1. Professional Android application development, Reto Meier, Wrox Programmer to Programmer, 2015. 2. Android Programming: The Big Nerd Ranch Guides, Phillips, B. & Hardy, B., 2nd Edition, 2014. 3. iOS Programming: The Big Nerd Ranch Guide, Conway, J., Hillegass, A., & Keur, C., 5th Edition, 2014.
  • 3. Creating and Saving Preferences To create or modify a Shared Preference, call getSharedPreferences on the application Context, passing in the name of the Shared Preferences to change. Shared Preferences are shared across an application’s components but aren’t available to other applications. Android provides many ways of storing data of an application. One of this way is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key, value pair. Android provides the SharedPreferences object to help you save simple application data. Using the SharedPreferences object, you can save the data you want through the use of key/value pairs, specify a key for the data you want to save, and then both it and its value will be saved automatically to an XML file.
  • 4. In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences. To modify a Shared Preference, use the SharedPreferences.Editor class. Get the Editor object by calling edit on the SharedPreferences object you want to change. To save edits, call commit on the Editor, as shown in the code snippet below. SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
  • 6. Retrieving Shared Preferences Accessing saved Shared Preferences is also done with the getSharedPreferences method. Pass in the name of the Shared Preference you want to access, and use the type-safe get<type> methods to extract saved values. Each getter takes a key and a default value (used when no value is available for that key), as shown in the skeleton code below:
  • 8. Persisting Data to Files Persistent data is data which you want to be available even after you fully close and restart your app. The three most common ways to safe this data locally is by using SharedPreferences, a local database or the file system (store data as a file). Android supports the following ways of storing data in the local file system:  Files - You can create and update files.  Preferences - Android allows you to save and retrieve persistent key-value pairs of primitive data type.  SQLite database - instances of SQLite databases are also stored on the local file system.
  • 9. Creating and Using Databases SQLite is a open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. Database - Package The main package is android.database.sqlite that contains the classes to manage your own databases. Database - Creation In order to create a database you just need to call this method openOrCreateDatabase with your database name and mode as a parameter. It returns an instance of SQLite database which you have to receive in your own object. Its syntax is given below.
  • 10. Database - Insertion we can create table or insert data into table using execSQL method defined in SQLiteDatabase class. Its syntax is given below:
  • 11. Database - Fetching We can retrieve anything from database using an object of the Cursor class. We will call a method of this class called rawQuery and it will return a resultset with the cursor pointing to the table. We can move the cursor forward and retrieve the data.
  • 12. Database - Helper class For managing all the operations related to the database , an helper class has been given and is called SQLiteOpenHelper. It automatically manages the creation and update of the database. Its syntax is given below: public class DBHelper extends SQLiteOpenHelper { public DBHelper() { super(context,DATABASE_NAME,null,1); } public void onCreate(SQLiteDatabase db) {} public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {} }