SlideShare a Scribd company logo
Databases in Android Application
Objectives 
 Know more about SQLite. 
 Understand the process on how to create 
database in an Android application using SQLite. 
 Use SQLite commands. 
 Enhance Android programming skills by 
incorporating database in an Android app.
Know More About SQLite. 
 SQLite is an Open Source database that supports 
standard relational database features like SQL 
syntax, transactions and prepared statements. 
 The database requires limited memory at 
runtime (approx. 250 Kbyte) 
 SQLite supports the data types TEXT (similar to 
String in Java), INTEGER (similar to long in Java) 
and REAL (similar to double in Java).
Know More About SQLite. 
 Uses a wrapper class, SQLiteOpenHelper which 
offers three basic API methods to interact with the 
database: 
 onCreate(SQLiteDatabase db), called when the 
database is created for the first time. 
 onOpen(SQLiteDatabase db), called when the database 
has been opened. 
 onUpgrade(SQLiteDatabase db, int oldVersion, int 
newVersion), called when the database needs to be 
upgraded.
Know More About SQLite. 
 The “Lite” in SQLite does not refer to its 
capabilities. Rather, SQLite is lightweight when it 
comes to setup complexity, administrative 
overhead, and resource usage. 
 Characteristics: 
 Server less 
 Zero Configuration 
 Self-Contained 
 Full-featured
Creating Database in an 
Android App using SQLite 
1. Design your database. 
Books 
Id Title Author 
1 Android Database Henry Williams 
2 Philippine History Jose Natividad
Creating Database in an 
Android App using SQLite 
2. Create a new Android 
Application project and 
design your UI.
Creating Database in an 
Android App using SQLite 
3. Add a class in the project that extends the 
SQLOpenHelper wrapper class.
Creating Database in an 
Android App using SQLite 
4.Doing so, will let you import necessary packages: 
5. Then add the database name and the database 
version.
Creating Database in an 
Android App using SQLite 
6. Add the constructor
Creating Database in an 
Android App using SQLite 
7. Add these two API methods:
Adding a Record to the 
Database 
1. To add a record, you need to create a method 
for that, but declare variables first:
Adding a Record to the 
Database 
2. Add the addBook method, with this you need 
to import ContentValues
Searching and Retrieving Data 
from the Database 
1. To search and retrieve data, you will have to 
use Cursor class.
Implementing Database 
1. On the MainActivity, add a method for getting user 
input and adding it to the database
Implementing Database 
2. Add another method, this time is searching 
for a book’s author based on the input title.
Implementing Database 
3. Set onClick on the xml properties of the Add and 
Search buttons. 
4. Run your app, fix bugs for errors. Add and search 
for the ff contents: 
Title Author 
Android Database Henry Williams 
Philippine History Jose Natividad
Laboratory Exercise: 
1. Open your PC, register to NetSupport. 
2. Open Exercise4 from your Desktop. 
3. Read Exercise4 and follow the instructions 
carefully. 
4. Notify your instructor if any problems, or if done.
Updating Data 
public int updateBook(String title, String author) { 
SQLiteDatabase db = this.getWritableDatabase(); 
ContentValues values = new ContentValues(); 
values.put(key_title, title); 
values.put(key_author, author); 
int i = db.update(tblName, //table 
values, // column/value 
"title=?", // selections 
new String[] { String.valueOf(title) }); //selection args 
db.close(); 
return i; 
}
public void updateBookClick(View v){ 
MySQLiteHelper db=new MySQLiteHelper(this); 
EditText txtTitle=(EditText) findViewById(R.id.editText1); 
EditText txtAuthor=(EditText) findViewById(R.id.editText2); 
if ((txtTitle.getText().toString()).equalsIgnoreCase("")) 
Toast.makeText(getApplicationContext(), "Invalid, null field.", 
Toast.LENGTH_SHORT).show(); 
else { 
int i= db.updateBook(txtTitle.getText().toString(), txtAuthor.getText().toString()); 
Toast.makeText(getApplicationContext(), i + " updated", 
Toast.LENGTH_SHORT).show(); 
txtTitle.setText(""); 
txtAuthor.setText(""); 
} 
}
Deleting Data 
public void deleteBook(String title) { 
SQLiteDatabase db = this.getWritableDatabase(); 
db.delete(tblName, "title=?", new String[] { String.valueOf(title) 
}); 
db.close(); 
}
public void deleteBookClick(View v){ 
MySQLiteHelper db=new MySQLiteHelper(this); 
EditText txtTitle=(EditText) findViewById(R.id.editText1); 
EditText txtAuthor=(EditText) findViewById(R.id.editText2); 
if ((txtTitle.getText().toString()).equalsIgnoreCase("")) 
Toast.makeText(getApplicationContext(), "Invalid, null field.", 
Toast.LENGTH_SHORT).show(); 
else { 
db.deleteBook(txtTitle.getText().toString()); 
Toast.makeText(getApplicationContext(), "Book deleted", 
Toast.LENGTH_SHORT).show(); 
txtTitle.setText(""); 
txtAuthor.setText(""); 
} 
}
Activity Life Cycle
Activity Life Cycle 
 Resumed - In this state, the activity is in the foreground and 
the user can interact with it. (Also sometimes referred to as the 
"running" state.) 
 Paused - In this state, the activity is partially obscured by 
another activity—the other activity that's in the foreground is 
semi-transparent or doesn't cover the entire screen. The 
paused activity does not receive user input and cannot 
execute any code. 
 Stopped - In this state, the activity is completely hidden and 
not visible to the user; it is considered to be in the background. 
While stopped, the activity instance and all its state 
information such as member variables is retained, but it 
cannot execute any code.
Activity Life Cycle 
 The other states (Created and Started) are 
transient and the system quickly moves from 
them to the next state by calling the next 
lifecycle callback method. 
 That is, after the system calls onCreate(), it 
quickly calls onStart(), which is quickly 
followed by onResume().
Databases in Android Application
Databases in Android Application
protected void onStop() { 
super.onStop(); 
ContentValues values = new ContentValues(); 
values.put(NotePad.Notes.COLUMN_NAME_NOTE, 
getCurrentNoteText()); 
values.put(NotePad.Notes.COLUMN_NAME_TITLE, 
getCurrentNoteTitle()); 
getContentResolver().update( 
mUri, 
values, 
null, 
null 
} 
}
Ad

More Related Content

What's hot (20)

Android adapters
Android adaptersAndroid adapters
Android adapters
baabtra.com - No. 1 supplier of quality freshers
 
Computer Science:Java jdbc
Computer Science:Java jdbcComputer Science:Java jdbc
Computer Science:Java jdbc
St Mary's College,Thrissur,Kerala
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themes
Sourabh Sahu
 
JDBC
JDBCJDBC
JDBC
People Strategists
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
Padma Kannan
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Applets
AppletsApplets
Applets
Prabhakaran V M
 
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
Khaled Anaqwa
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
vishal choudhary
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
Muthukumaran Subramanian
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
Hareem Naz
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 

Viewers also liked (20)

Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
Adil Mehmoood
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Sqlite
SqliteSqlite
Sqlite
Kumar
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java JDBC Communication and Connection Manager
Java JDBC Communication and Connection ManagerJava JDBC Communication and Connection Manager
Java JDBC Communication and Connection Manager
aashish
 
JDBC
JDBCJDBC
JDBC
raginihacks
 
jdbc document
jdbc documentjdbc document
jdbc document
Yamuna Devi
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
kamal kotecha
 
jsp MySQL database connectivity
jsp MySQL database connectivityjsp MySQL database connectivity
jsp MySQL database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Jdbc
JdbcJdbc
Jdbc
Jussi Pohjolainen
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Jdbc
JdbcJdbc
Jdbc
Yamuna Devi
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
Pooja Talreja
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
Dharani Kumar Madduri
 
JAVA AND MYSQL QUERIES
JAVA AND MYSQL QUERIES JAVA AND MYSQL QUERIES
JAVA AND MYSQL QUERIES
Aditya Shah
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
Waheed Warraich
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
Adil Mehmoood
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Sqlite
SqliteSqlite
Sqlite
Kumar
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Java JDBC Communication and Connection Manager
Java JDBC Communication and Connection ManagerJava JDBC Communication and Connection Manager
Java JDBC Communication and Connection Manager
aashish
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
kamal kotecha
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
Pooja Talreja
 
JAVA AND MYSQL QUERIES
JAVA AND MYSQL QUERIES JAVA AND MYSQL QUERIES
JAVA AND MYSQL QUERIES
Aditya Shah
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Ad

Similar to Databases in Android Application (20)

Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
vishal choudhary
 
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
Aravindharamanan S
 
Notepad tutorial
Notepad tutorialNotepad tutorial
Notepad tutorial
info_zybotech
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
Perfect APK
 
Chapter6 database connectivity
Chapter6 database connectivityChapter6 database connectivity
Chapter6 database connectivity
KV(AFS) Utarlai, Barmer (Rajasthan)
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
Jaoo - Open Social A Standard For The Social Web
Jaoo - Open Social A Standard For The Social WebJaoo - Open Social A Standard For The Social Web
Jaoo - Open Social A Standard For The Social Web
Patrick Chanezon
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
Steve Xu
 
I am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfI am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdf
Conint29
 
Lecture 10: Android SQLite database.pptx
Lecture 10: Android SQLite database.pptxLecture 10: Android SQLite database.pptx
Lecture 10: Android SQLite database.pptx
Yousef Alamir
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
Mobile Application Development (local database) class-07
Mobile Application Development (local database) class-07Mobile Application Development (local database) class-07
Mobile Application Development (local database) class-07
Dr. Mazin Mohamed alkathiri
 
Sq lite
Sq liteSq lite
Sq lite
vinoth raj
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
jillisacebi75827
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Syed Shahul
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
niraj57
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
vishal choudhary
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
Perfect APK
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
Jaoo - Open Social A Standard For The Social Web
Jaoo - Open Social A Standard For The Social WebJaoo - Open Social A Standard For The Social Web
Jaoo - Open Social A Standard For The Social Web
Patrick Chanezon
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
Steve Xu
 
I am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdfI am looking for some assistance with SQLite database. I have tried se.pdf
I am looking for some assistance with SQLite database. I have tried se.pdf
Conint29
 
Lecture 10: Android SQLite database.pptx
Lecture 10: Android SQLite database.pptxLecture 10: Android SQLite database.pptx
Lecture 10: Android SQLite database.pptx
Yousef Alamir
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
Mobile Application Development (local database) class-07
Mobile Application Development (local database) class-07Mobile Application Development (local database) class-07
Mobile Application Development (local database) class-07
Dr. Mazin Mohamed alkathiri
 
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdfThis is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
This is the official tutorial from Oracle.httpdocs.oracle.comj.pdf
jillisacebi75827
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Syed Shahul
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
TAISEEREISA
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
niraj57
 
Ad

Databases in Android Application

  • 2. Objectives  Know more about SQLite.  Understand the process on how to create database in an Android application using SQLite.  Use SQLite commands.  Enhance Android programming skills by incorporating database in an Android app.
  • 3. Know More About SQLite.  SQLite is an Open Source database that supports standard relational database features like SQL syntax, transactions and prepared statements.  The database requires limited memory at runtime (approx. 250 Kbyte)  SQLite supports the data types TEXT (similar to String in Java), INTEGER (similar to long in Java) and REAL (similar to double in Java).
  • 4. Know More About SQLite.  Uses a wrapper class, SQLiteOpenHelper which offers three basic API methods to interact with the database:  onCreate(SQLiteDatabase db), called when the database is created for the first time.  onOpen(SQLiteDatabase db), called when the database has been opened.  onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion), called when the database needs to be upgraded.
  • 5. Know More About SQLite.  The “Lite” in SQLite does not refer to its capabilities. Rather, SQLite is lightweight when it comes to setup complexity, administrative overhead, and resource usage.  Characteristics:  Server less  Zero Configuration  Self-Contained  Full-featured
  • 6. Creating Database in an Android App using SQLite 1. Design your database. Books Id Title Author 1 Android Database Henry Williams 2 Philippine History Jose Natividad
  • 7. Creating Database in an Android App using SQLite 2. Create a new Android Application project and design your UI.
  • 8. Creating Database in an Android App using SQLite 3. Add a class in the project that extends the SQLOpenHelper wrapper class.
  • 9. Creating Database in an Android App using SQLite 4.Doing so, will let you import necessary packages: 5. Then add the database name and the database version.
  • 10. Creating Database in an Android App using SQLite 6. Add the constructor
  • 11. Creating Database in an Android App using SQLite 7. Add these two API methods:
  • 12. Adding a Record to the Database 1. To add a record, you need to create a method for that, but declare variables first:
  • 13. Adding a Record to the Database 2. Add the addBook method, with this you need to import ContentValues
  • 14. Searching and Retrieving Data from the Database 1. To search and retrieve data, you will have to use Cursor class.
  • 15. Implementing Database 1. On the MainActivity, add a method for getting user input and adding it to the database
  • 16. Implementing Database 2. Add another method, this time is searching for a book’s author based on the input title.
  • 17. Implementing Database 3. Set onClick on the xml properties of the Add and Search buttons. 4. Run your app, fix bugs for errors. Add and search for the ff contents: Title Author Android Database Henry Williams Philippine History Jose Natividad
  • 18. Laboratory Exercise: 1. Open your PC, register to NetSupport. 2. Open Exercise4 from your Desktop. 3. Read Exercise4 and follow the instructions carefully. 4. Notify your instructor if any problems, or if done.
  • 19. Updating Data public int updateBook(String title, String author) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(key_title, title); values.put(key_author, author); int i = db.update(tblName, //table values, // column/value "title=?", // selections new String[] { String.valueOf(title) }); //selection args db.close(); return i; }
  • 20. public void updateBookClick(View v){ MySQLiteHelper db=new MySQLiteHelper(this); EditText txtTitle=(EditText) findViewById(R.id.editText1); EditText txtAuthor=(EditText) findViewById(R.id.editText2); if ((txtTitle.getText().toString()).equalsIgnoreCase("")) Toast.makeText(getApplicationContext(), "Invalid, null field.", Toast.LENGTH_SHORT).show(); else { int i= db.updateBook(txtTitle.getText().toString(), txtAuthor.getText().toString()); Toast.makeText(getApplicationContext(), i + " updated", Toast.LENGTH_SHORT).show(); txtTitle.setText(""); txtAuthor.setText(""); } }
  • 21. Deleting Data public void deleteBook(String title) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(tblName, "title=?", new String[] { String.valueOf(title) }); db.close(); }
  • 22. public void deleteBookClick(View v){ MySQLiteHelper db=new MySQLiteHelper(this); EditText txtTitle=(EditText) findViewById(R.id.editText1); EditText txtAuthor=(EditText) findViewById(R.id.editText2); if ((txtTitle.getText().toString()).equalsIgnoreCase("")) Toast.makeText(getApplicationContext(), "Invalid, null field.", Toast.LENGTH_SHORT).show(); else { db.deleteBook(txtTitle.getText().toString()); Toast.makeText(getApplicationContext(), "Book deleted", Toast.LENGTH_SHORT).show(); txtTitle.setText(""); txtAuthor.setText(""); } }
  • 24. Activity Life Cycle  Resumed - In this state, the activity is in the foreground and the user can interact with it. (Also sometimes referred to as the "running" state.)  Paused - In this state, the activity is partially obscured by another activity—the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen. The paused activity does not receive user input and cannot execute any code.  Stopped - In this state, the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.
  • 25. Activity Life Cycle  The other states (Created and Started) are transient and the system quickly moves from them to the next state by calling the next lifecycle callback method.  That is, after the system calls onCreate(), it quickly calls onStart(), which is quickly followed by onResume().
  • 28. protected void onStop() { super.onStop(); ContentValues values = new ContentValues(); values.put(NotePad.Notes.COLUMN_NAME_NOTE, getCurrentNoteText()); values.put(NotePad.Notes.COLUMN_NAME_TITLE, getCurrentNoteTitle()); getContentResolver().update( mUri, values, null, null } }