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

Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andevMike Nakhimovich
 
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 & ReduxVisual Engineering
 
Deep Dive into React Hooks
Deep Dive into React HooksDeep Dive into React Hooks
Deep Dive into React HooksFelix Kühl
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionVisual Engineering
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshopNir Kaufman
 
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 tutorialKaty Slemon
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and reduxCuong Ho
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0Jeado Ko
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practicesClickky
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
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 Ross Dederer
 
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 SideVisual Engineering
 

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 Introductionmsimkin
 
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 PermissionsHariharan Ganesan
 
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 1Ibnu Sina Wardy
 
Android permission system
Android permission systemAndroid permission system
Android permission systemShivang Goel
 
Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009Web Services and Android - OSSPAC 2009
Web Services and Android - OSSPAC 2009sullis
 
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 shopAbhinav Mishra
 
Android permission system
Android permission systemAndroid permission system
Android permission systemShivang Goel
 
Android secuirty permission - upload
Android secuirty   permission - uploadAndroid secuirty   permission - upload
Android secuirty permission - uploadBin Yang
 
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 TutorialPerfect APK
 
Simple JSON parser
Simple JSON parserSimple JSON parser
Simple JSON parserDongjun Lee
 
Android webservices
Android webservicesAndroid webservices
Android webservicesKrazy Koder
 
Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011Android porting for dummies @droidconin 2011
Android porting for dummies @droidconin 2011pundiramit
 
Android json parser tutorial – example
Android json parser tutorial – exampleAndroid json parser tutorial – example
Android json parser tutorial – exampleRajat Ghai
 

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_DBUniFabric
 
Java on Google App engine
Java on Google App engineJava on Google App engine
Java on Google App engineMichael Parker
 
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.1Matthew Barlocker
 
Perl Tools for Productivity
Perl Tools for ProductivityPerl Tools for Productivity
Perl Tools for ProductivityTudor Constantin
 
Yaetos Tech Overview
Yaetos Tech OverviewYaetos Tech Overview
Yaetos Tech Overviewprevota
 
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 ModuleKatie Gulley
 
Drools & jBPM future roadmap talk
Drools & jBPM future roadmap talkDrools & jBPM future roadmap talk
Drools & jBPM future roadmap talkMark Proctor
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming TechniquesRaji Ghawi
 
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).pdfAppster1
 
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.pdfAppster1
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteChris Baynes
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
OSGi Cloud Ecosystems - David Bosschaert
OSGi Cloud Ecosystems - David BosschaertOSGi Cloud Ecosystems - David Bosschaert
OSGi Cloud Ecosystems - David Bosschaertmfrancis
 
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 WebSocketsAndrei Sebastian Cîmpean
 
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 EngineerAmaaira Johns
 
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 2015Dave Stokes
 

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

Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2Vivek Bhusal
 
Training Session 2
Training Session 2 Training Session 2
Training Session 2 Vivek Bhusal
 
Android training day 3
Android training day 3Android training day 3
Android training day 3Vivek Bhusal
 
Android training day 1
Android training day 1Android training day 1
Android training day 1Vivek Bhusal
 
Stores munk presentation_aug10 (1)
Stores munk presentation_aug10 (1)Stores munk presentation_aug10 (1)
Stores munk presentation_aug10 (1)Vivek Bhusal
 
Wisevote - opendataweek @
Wisevote - opendataweek @Wisevote - opendataweek @
Wisevote - opendataweek @Vivek Bhusal
 
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 bootcampVivek Bhusal
 

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

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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);