SlideShare a Scribd company logo
1 of 22
Android Apps Development – Training
Day 4
Android Storage
● How do you save your application data ?
– SharedPreferences*
● Storage in key-value pairs.
– Internal Storage
● Storage on device memory
– External Storage
● Storage on shared external storage
– SQLite Databases*
●
Store structured data in a private database
– Network Connections
● Store data on web
SharedPreferences
● The way android stores users preferences
● But why SharedPreferences ?
– Ease of implementation
– Faster in terms of coding
– Accessibility of key values
– Suitable for the small things
● e.g. Game difficulty level, user name, user accounts,
etc.
I got your
back buddy !
SharedPreferences
● Every thing is saved in terms of key-value
– e.g. “NAME”, “Android”
“PhoneNumber”, “1234”
● For the implementation we will be using the:
– SharedPreferences
● General framework to save and retrieve persistent key-value pairs
– Editor
● Interface used for modifying values in a SharedPreferences object
● Use of commit() or apply() to make changes persist
Implementation
public class ProjectPreference{
SharedPreferences pref;
Editor editor;
Context _context;
int PRIVATE_MODE = 0;
private static final String PREF_NAME = “prefmyapp”;
... (A)
public ProjectPreference(Context context){
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
} ... (B)
Accessing the
SharedPreferences this
way gives you more
flexibility
We are creating a
separate class
here
A: Define Variables
● Suppose we have a contact to save:
– Name
– Address
– Number
● Declare them:
public static final String KEY_NAME = “name”;
public static final String KEY_ADD = “address”;
public static final String KEY_NUM = “number”;
B: Define Getters and Setters
● Defining setters and getters
– void for setters
public void setName(String key, String value){
editor.putString(key, value);
editor.commit();
}
– <types> for getters
public String getName(String key){
return pref.getString(key, “”);
}
You can
define your default
values here
Accessing SharedPreferences
● Create an object
ProjectPreference SM;
● Initialize
SM = new ProjectPreference(Class.this);
● Access variables and methods
SM.getName(SM.KEY_NAME);
● Set values
SM.setName(SM.KEY_NAME, “Android”);
Building the application
SQLite Database
● SQLite is innate in every Android device
– No need for extra setup etc.
● We only have to define the SQL statements for
creating and updating the database
● All commands regarding creating tables,
inserting values etc. are the same as in SQL
SharedPreferenes
VS
SQLite
● SQLite provides capability of more complex
storage
– Storage for large number of data
– Higher capabilities
● e.g. in the loadshedding app we notice that we do not
have to update the app every time a new schedule
arrives.
SQLite in Android
● Android should use a DBHelper
– extends SQLiteOpenHelper class
● Two main methods:
– onCreate()
● Creates the database, parameters needed:
● DATABASE_NAME
● DATABASE_VERSION
– onUpgrade()
● Updates the current database depending upon:
● DATABASE_VERSION
● All operations regarding the database is to be
performed by the SQLiteDatabase object
● Either the:
– getWritableDatabase() : Write mode
– getReadableDatabase() : Read mode
used with the SQLiteDatabase object.
SQLiteDatabase db = this.getWritableDatabase()
db.insert(...)
● While using the SELECT operations we use the
Cursor object
– Cursor is something similar to an iterator
if(cursor.moveToFirst())
{
do { …
} while(cursor.moveToLast())
}
– Also during the query we use a rawQuery() method
● In insert operations we use the ContentValues
object.
– ContentValues values = new ContentValues( );
values.put("name" , "ABC");
values.put("phoneNumber" , "123");
db.insert(table, null, values);
● While programming create the following
functions:
– Getting a single row
– Getting all rows
– Getting row count
– Updating row
– Deleting row
For better SQLite implementation
● Create both:
– Data Model class
● With all the setters and getters
– Data Handler
● Extending the SQLiteOpenHelper
Implementing SQLite
Insert user
data into
database
Redirect user into
another activity
showing the
database
AsyncTask
● What is threading ?
– The way any computing device responds to its
commands
● Android only uses a main thread by default for
its application
● The main thread processes the following:
– Application UI
– User inputs to the application
Is this enough?
● While processing heavy/ time consuming task,
the UI will freeze until the task is complete
– Bad practice
● For these tasks open a separate thread
– ASYNCTASK
● Asynctask is android's multitasker
● Methods inside the AsyncTask
– OnPreExecute()
● Generally used to load the progress bar
– doInBackground(Params... )
● All the logic is dumped here
– OnProgressUpdate()
● Called when publishProgress() is called in the
doInBackground()
– onPostExecute(Result)
● Gives out the desired result
● Using the AsyncTask
– Extend the AsyncTask
class Abc extends AsyncTask<Params,Progress,Result>
● Params: the input, what you pass into the AsyncTask
● Progress: on updates, passed to onProgressUpdate()
● Result: the output from doInBackground() returned to
the onPostExecute()
– Call on the AsyncTask
new Abc.execute(Params);

More Related Content

What's hot

What's hot (20)

Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University - Exploring Angular 2
Commit University - Exploring Angular 2
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
React hooks
React hooksReact hooks
React hooks
 
Deep Dive into React Hooks
Deep Dive into React HooksDeep Dive into React Hooks
Deep Dive into React Hooks
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Angular2
Angular2Angular2
Angular2
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshop
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorial
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
React with Redux
React with ReduxReact with Redux
React with Redux
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Speed up your GWT coding with gQuery
Speed up your GWT coding with gQuerySpeed up your GWT coding with gQuery
Speed up your GWT coding with gQuery
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 

Viewers also liked

Sandbox Introduction
Sandbox IntroductionSandbox Introduction
Sandbox Introduction
msimkin
 
Android webservices
Android webservicesAndroid webservices
Android webservices
Krazy Koder
 

Viewers also liked (20)

Sandbox Introduction
Sandbox IntroductionSandbox Introduction
Sandbox Introduction
 
Security threats in Android OS + App Permissions
Security threats in Android OS + App PermissionsSecurity threats in Android OS + App Permissions
Security threats in Android OS + App Permissions
 
Tips dan Third Party Library untuk Android - Part 1
Tips dan Third Party Library untuk Android - Part 1Tips dan Third Party Library untuk Android - Part 1
Tips dan Third Party Library untuk Android - Part 1
 
Android(1)
Android(1)Android(1)
Android(1)
 
Android permission system
Android permission systemAndroid permission system
Android permission system
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009
 
Anatomizing online payment systems: hack to shop
Anatomizing online payment systems: hack to shopAnatomizing online payment systems: hack to shop
Anatomizing online payment systems: hack to shop
 
Android permission system
Android permission systemAndroid permission system
Android permission system
 
Android secuirty permission - upload
Android secuirty   permission - uploadAndroid secuirty   permission - upload
Android secuirty permission - upload
 
Android 6.0 permission change
Android 6.0 permission changeAndroid 6.0 permission change
Android 6.0 permission change
 
Android AsyncTask Tutorial
Android AsyncTask TutorialAndroid AsyncTask Tutorial
Android AsyncTask Tutorial
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 
Basic Android Push Notification
Basic Android Push NotificationBasic Android Push Notification
Basic Android Push Notification
 
Android new permission model
Android new permission modelAndroid new permission model
Android new permission model
 
JSON overview and demo
JSON overview and demoJSON overview and demo
JSON overview and demo
 
Simple JSON parser
Simple JSON parserSimple JSON parser
Simple JSON parser
 
App Permissions
App PermissionsApp Permissions
App Permissions
 
Android webservices
Android webservicesAndroid webservices
Android webservices
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011
 
Android json parser tutorial – example
Android json parser tutorial – exampleAndroid json parser tutorial – example
Android json parser tutorial – example
 

Similar to Android training day 4

SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DB
UniFabric
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
Katie Gulley
 

Similar to Android training day 4 (20)

SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DB
 
Java on Google App engine
Java on Google App engineJava on Google App engine
Java on Google App engine
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1
 
Perl Tools for Productivity
Perl Tools for ProductivityPerl Tools for Productivity
Perl Tools for Productivity
 
Yaetos Tech Overview
Yaetos Tech OverviewYaetos Tech Overview
Yaetos Tech Overview
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
 
Stmik bandung
Stmik bandungStmik bandung
Stmik bandung
 
Drools & jBPM future roadmap talk
Drools & jBPM future roadmap talkDrools & jBPM future roadmap talk
Drools & jBPM future roadmap talk
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
OSGi Cloud Ecosystems - David Bosschaert
OSGi Cloud Ecosystems - David BosschaertOSGi Cloud Ecosystems - David Bosschaert
OSGi Cloud Ecosystems - David Bosschaert
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
Get Ready to Become Google Associate Cloud Engineer
Get Ready to Become Google Associate Cloud EngineerGet Ready to Become Google Associate Cloud Engineer
Get Ready to Become Google Associate Cloud Engineer
 
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 

More from Vivek Bhusal (9)

Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
 
Training Session 2
Training Session 2 Training Session 2
Training Session 2
 
Android training day 3
Android training day 3Android training day 3
Android training day 3
 
Android training day 1
Android training day 1Android training day 1
Android training day 1
 
Stores munk presentation_aug10 (1)
Stores munk presentation_aug10 (1)Stores munk presentation_aug10 (1)
Stores munk presentation_aug10 (1)
 
Mybudget
MybudgetMybudget
Mybudget
 
Wisevote - opendataweek @
Wisevote - opendataweek @Wisevote - opendataweek @
Wisevote - opendataweek @
 
Android training at GDG kathmandu Startup weekend bootcamp
Android training at GDG kathmandu Startup weekend bootcampAndroid training at GDG kathmandu Startup weekend bootcamp
Android training at GDG kathmandu Startup weekend bootcamp
 
My medical info
My medical infoMy medical info
My medical info
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Android training day 4

  • 1. Android Apps Development – Training Day 4
  • 2. Android Storage ● How do you save your application data ? – SharedPreferences* ● Storage in key-value pairs. – Internal Storage ● Storage on device memory – External Storage ● Storage on shared external storage – SQLite Databases* ● Store structured data in a private database – Network Connections ● Store data on web
  • 3. SharedPreferences ● The way android stores users preferences ● But why SharedPreferences ? – Ease of implementation – Faster in terms of coding – Accessibility of key values – Suitable for the small things ● e.g. Game difficulty level, user name, user accounts, etc. I got your back buddy !
  • 4. SharedPreferences ● Every thing is saved in terms of key-value – e.g. “NAME”, “Android” “PhoneNumber”, “1234” ● For the implementation we will be using the: – SharedPreferences ● General framework to save and retrieve persistent key-value pairs – Editor ● Interface used for modifying values in a SharedPreferences object ● Use of commit() or apply() to make changes persist
  • 5. Implementation public class ProjectPreference{ SharedPreferences pref; Editor editor; Context _context; int PRIVATE_MODE = 0; private static final String PREF_NAME = “prefmyapp”; ... (A) public ProjectPreference(Context context){ this._context = context; pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); editor = pref.edit(); } ... (B) Accessing the SharedPreferences this way gives you more flexibility We are creating a separate class here
  • 6. A: Define Variables ● Suppose we have a contact to save: – Name – Address – Number ● Declare them: public static final String KEY_NAME = “name”; public static final String KEY_ADD = “address”; public static final String KEY_NUM = “number”;
  • 7. B: Define Getters and Setters ● Defining setters and getters – void for setters public void setName(String key, String value){ editor.putString(key, value); editor.commit(); } – <types> for getters public String getName(String key){ return pref.getString(key, “”); } You can define your default values here
  • 8. Accessing SharedPreferences ● Create an object ProjectPreference SM; ● Initialize SM = new ProjectPreference(Class.this); ● Access variables and methods SM.getName(SM.KEY_NAME); ● Set values SM.setName(SM.KEY_NAME, “Android”);
  • 10. SQLite Database ● SQLite is innate in every Android device – No need for extra setup etc. ● We only have to define the SQL statements for creating and updating the database ● All commands regarding creating tables, inserting values etc. are the same as in SQL
  • 11. SharedPreferenes VS SQLite ● SQLite provides capability of more complex storage – Storage for large number of data – Higher capabilities ● e.g. in the loadshedding app we notice that we do not have to update the app every time a new schedule arrives.
  • 12. SQLite in Android ● Android should use a DBHelper – extends SQLiteOpenHelper class ● Two main methods: – onCreate() ● Creates the database, parameters needed: ● DATABASE_NAME ● DATABASE_VERSION – onUpgrade() ● Updates the current database depending upon: ● DATABASE_VERSION
  • 13. ● All operations regarding the database is to be performed by the SQLiteDatabase object ● Either the: – getWritableDatabase() : Write mode – getReadableDatabase() : Read mode used with the SQLiteDatabase object. SQLiteDatabase db = this.getWritableDatabase() db.insert(...)
  • 14. ● While using the SELECT operations we use the Cursor object – Cursor is something similar to an iterator if(cursor.moveToFirst()) { do { … } while(cursor.moveToLast()) } – Also during the query we use a rawQuery() method
  • 15. ● In insert operations we use the ContentValues object. – ContentValues values = new ContentValues( ); values.put("name" , "ABC"); values.put("phoneNumber" , "123"); db.insert(table, null, values);
  • 16. ● While programming create the following functions: – Getting a single row – Getting all rows – Getting row count – Updating row – Deleting row
  • 17. For better SQLite implementation ● Create both: – Data Model class ● With all the setters and getters – Data Handler ● Extending the SQLiteOpenHelper
  • 18. Implementing SQLite Insert user data into database Redirect user into another activity showing the database
  • 19. AsyncTask ● What is threading ? – The way any computing device responds to its commands ● Android only uses a main thread by default for its application ● The main thread processes the following: – Application UI – User inputs to the application Is this enough?
  • 20. ● While processing heavy/ time consuming task, the UI will freeze until the task is complete – Bad practice ● For these tasks open a separate thread – ASYNCTASK ● Asynctask is android's multitasker
  • 21. ● Methods inside the AsyncTask – OnPreExecute() ● Generally used to load the progress bar – doInBackground(Params... ) ● All the logic is dumped here – OnProgressUpdate() ● Called when publishProgress() is called in the doInBackground() – onPostExecute(Result) ● Gives out the desired result
  • 22. ● Using the AsyncTask – Extend the AsyncTask class Abc extends AsyncTask<Params,Progress,Result> ● Params: the input, what you pass into the AsyncTask ● Progress: on updates, passed to onProgressUpdate() ● Result: the output from doInBackground() returned to the onPostExecute() – Call on the AsyncTask new Abc.execute(Params);