SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Android Persistance Data
using SQLite Database
How I am
Name : Arif Akbarul Huda
Job : Lecture | Programmer | Book Writer | Researcher
Office : qiscus , AMIKOM, home
Socmed : @omayib , http://id.linkedin.com/in/akbarul
My contribution...
Qiscus [kis-kas] (noun). Perusahaan teknologi yang
menyediakan layanan pesan instan dan komunikasi untuk
tempat kerja. Perusahaan ini didirikan di Singapura pada
tahun 2013 dan memiliki pusat riset dan pengembangan
teknologi di Yogyakarta, Indonesia.[1]
(https://id.wikipedia.org/wiki/Qiscus)
Lets begin
How they manage the data?
Saving data
Shared
Preference
File
Storage
SQLite
Cloud
what kind of storage we need?
It is depend on your data type and structure
SQLite Database
[se-kyu-lait]
TodoList Application
Source :
https://github.com/omayib/TodoList/tree/feature/sqlite
What is SQLite?
● Opensource db
● For limited memory devices
● Support SQL syntax dan transaction.
SQLite database file location
DATA/data/package/databases/fileDatabase.db
SQLite Data Type
● NULL
● Integer
● Real
● Text
● Bloob
SQLite Component
SQLiteOpenHelper
-onCreate()
-onUpdgrade()
SqliteDatabase
- insert()
- update()
- delete()
- execSQL()
Cursor
- getCount()
- getInt()
- getString()
A helper class to manage
database creation and
version management
has methods to create, delete,
execute SQL commands,
and perform other common
database management tasks
the result set returned
by a database query
Simple and clean architecture
Design your code like a puzzle
Todolist Application Architechture
UI
Model domain repository
SQlite Cloud..
Todolist Application Architechture
LocalDatabaseConfiguration configDb = new LocalDatabaseConfiguration(this,
“databaseName.db”, null, 1);
#1. Make a configuration for our SQLite database
#2. Initiate the repository
TodoRepository repo = new TodoRepository(configDb);
Database
Creation
#4. insert an item
Todo newTodo = new Todo(”randomId”,”beli makan!”);
repo.insert(newTodo);
#5. update an item
Todo itemTobUpdated = new Todo(”randomId”,”beli makan!”);
repo.update(itemTobUpdated);
#6. update an item
Todo itemTobeDeleted = new Todo(”randomId”,”beli makan!”);
repo.delete(itemTobeDeleted);
#3. get all todo items
List<Todo> todos = repo.findAll()
Database
Querying
Show me the code!
Performance
E/Database(234): Leak found
E/Database(234): Caused by:
java.lang.IllegalStateException: SQL iteDatabase created
and never closed
Open the database but forgot to close it
Possible Solution :
- make SQLiteDataBaseOpenHelper as Single Instance
- initiate inside Application
public class DatabaseHelper extends SQLiteOpenHelper {
private static DatabaseHelper sInstance;
private static final String DATABASE_NAME = "database_name";
private static final String DATABASE_TABLE = "table_name";
private static final int DATABASE_VERSION = 1;
public static synchronized DatabaseHelper getInstance(Context context) {
if (sInstance == null) {
sInstance = new DatabaseHelper(context.getApplicationContext());
}
return sInstance;
}
private DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
public class TodoApplication extends Application {
private TodoRepository repository;
@Override
public void onCreate() {
super.onCreate();
LocalDatabaseConfiguration localDatabaseConfiguration =new
LocalDatabaseConfiguration(this, LocalDatabaseConfiguration.DATABASE_NAME,
null, LocalDatabaseConfiguration.DATABSE_VERSION);
repository =new TodoRepository(localDatabaseConfiguration);
}
public TodoRepository getRepository() {
return repository;
}
}
ACID
(atomic, consistent, isolated, durable)
Handling multiple transaction and
large data
   
   db.beginTransaction();
   try {
        for (int i= 0; i< values.lenght; i++){
           // TODO prepare ContentValues object values
           db.insert(your_table, null, values);
           // In case you do larger updates
        }
        db.setTransactionSuccessful();     
    } finally {
   db.endTransaction();
   } 
//
end

Más contenido relacionado

La actualidad más candente

Android datastorage
Android datastorageAndroid datastorage
Android datastorage
Krazy Koder
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
Stanley Huang
 

La actualidad más candente (20)

Better Data Persistence on Android
Better Data Persistence on AndroidBetter Data Persistence on Android
Better Data Persistence on Android
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
 
Sqlite
SqliteSqlite
Sqlite
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
 
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
ANDROID USING SQLITE DATABASE ADMINISTRATORS ~HMFTJ
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
 
Using sqlite database in android with sqlite manager browser add ons
Using sqlite database in android with sqlite manager browser add onsUsing sqlite database in android with sqlite manager browser add ons
Using sqlite database in android with sqlite manager browser add ons
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
Sqlite
SqliteSqlite
Sqlite
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Introduction to SQLite: The Most Popular Database in the World
Introduction to SQLite: The Most Popular Database in the WorldIntroduction to SQLite: The Most Popular Database in the World
Introduction to SQLite: The Most Popular Database in the World
 
SQLite 3
SQLite 3SQLite 3
SQLite 3
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Advanced Core Data
Advanced Core DataAdvanced Core Data
Advanced Core Data
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
 
Persistence on iOS
Persistence on iOSPersistence on iOS
Persistence on iOS
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
SQLite - Overview
SQLite - OverviewSQLite - Overview
SQLite - Overview
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
[Android] Data Storage
[Android] Data Storage[Android] Data Storage
[Android] Data Storage
 

Similar a Persitance Data with sqlite

Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
Toby Samples
 
Eat whatever you can with PyBabe
Eat whatever you can with PyBabeEat whatever you can with PyBabe
Eat whatever you can with PyBabe
Dataiku
 
Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...
Shakir Majeed Khan
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
Joe Jacob
 

Similar a Persitance Data with sqlite (20)

Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
 
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
最近 node.js 來勢洶洶, 怎麼辦? 別怕, 我們也有秘密武器 RingoJS!
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
 
Sq lite database
Sq lite databaseSq lite database
Sq lite database
 
Indexed db
Indexed dbIndexed db
Indexed db
 
Rajab Davudov - Android Database
Rajab Davudov - Android DatabaseRajab Davudov - Android Database
Rajab Davudov - Android Database
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 
iOS & Drupal
iOS & DrupaliOS & Drupal
iOS & Drupal
 
Eat whatever you can with PyBabe
Eat whatever you can with PyBabeEat whatever you can with PyBabe
Eat whatever you can with PyBabe
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenches
 
Using Play Framework 2 in production
Using Play Framework 2 in productionUsing Play Framework 2 in production
Using Play Framework 2 in production
 
Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...Sharepoint Saturday India Online best practice for developing share point sol...
Sharepoint Saturday India Online best practice for developing share point sol...
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
 
Simpler Core Data with RubyMotion
Simpler Core Data with RubyMotionSimpler Core Data with RubyMotion
Simpler Core Data with RubyMotion
 
Saving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroSaving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio Haro
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data Persistence
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
 

Más de Arif Huda

Más de Arif Huda (20)

Spotify Recommender System
Spotify Recommender SystemSpotify Recommender System
Spotify Recommender System
 
Startup Tanpa Mentor, Bisa?
Startup Tanpa Mentor, Bisa?Startup Tanpa Mentor, Bisa?
Startup Tanpa Mentor, Bisa?
 
Introducing Startup 101
Introducing Startup 101Introducing Startup 101
Introducing Startup 101
 
Solusi Mencegah Coding Ruwet
Solusi Mencegah Coding RuwetSolusi Mencegah Coding Ruwet
Solusi Mencegah Coding Ruwet
 
Bedah Teknologi Semacam Gojek
Bedah Teknologi Semacam GojekBedah Teknologi Semacam Gojek
Bedah Teknologi Semacam Gojek
 
Rahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 Tahun
Rahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 TahunRahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 Tahun
Rahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 Tahun
 
Membuat Media Edukasi Daring
Membuat Media Edukasi DaringMembuat Media Edukasi Daring
Membuat Media Edukasi Daring
 
Single responsibility pattern
Single responsibility patternSingle responsibility pattern
Single responsibility pattern
 
5 jalan rahasia mewujudkan ide startup
5 jalan rahasia mewujudkan ide startup5 jalan rahasia mewujudkan ide startup
5 jalan rahasia mewujudkan ide startup
 
programmersworld
programmersworldprogrammersworld
programmersworld
 
5 Langkah Jitu Melejitkan Ide Bisnis Startup
5 Langkah Jitu Melejitkan Ide Bisnis Startup5 Langkah Jitu Melejitkan Ide Bisnis Startup
5 Langkah Jitu Melejitkan Ide Bisnis Startup
 
getting started startup in millenial era
getting started startup in millenial eragetting started startup in millenial era
getting started startup in millenial era
 
Fingertip Detection
Fingertip DetectionFingertip Detection
Fingertip Detection
 
Protocol oriented programming
Protocol oriented programmingProtocol oriented programming
Protocol oriented programming
 
an implementation of repository pattern for mobile application
an implementation of repository pattern for mobile applicationan implementation of repository pattern for mobile application
an implementation of repository pattern for mobile application
 
Inovasi Teknologi Berkemajuan
Inovasi Teknologi BerkemajuanInovasi Teknologi Berkemajuan
Inovasi Teknologi Berkemajuan
 
Git workflow
Git workflowGit workflow
Git workflow
 
Media pembelajaran audio untuk tunanetra
Media pembelajaran audio untuk tunanetraMedia pembelajaran audio untuk tunanetra
Media pembelajaran audio untuk tunanetra
 
Tobe a superstar programmer
Tobe a superstar programmerTobe a superstar programmer
Tobe a superstar programmer
 
clean code for high quality software
clean code for high quality softwareclean code for high quality software
clean code for high quality software
 

Último

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
 

Último (8)

FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 

Persitance Data with sqlite