Data Persistence in Android

Slides:



Advertisements
Similar presentations
Programming with Android: Data management
Advertisements

Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
 data/data-storage.html#pref data/data-storage.html#pref 
Tracking & Login Data persistence User tracking.
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Cosc 5/4730 Android and Blackberry SQLite. For the sql language syntax, please see SQlite documentation –
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
Data Storage: Part 1 (Preferences)
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Database Rung-Hung Gau Department of Computer Science and Engineering
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
Cosc 5/4730 Android Content Providers and Intents.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
Android Storage. There are several options for storage of data with Android We can put data into a preferences file. We can put data into a ‘normal’ file.
Nilesh Singh Local Data Storage option Android provides several options for you to save persistent application data. - Shared preferences - Creation.
Data persistence How to save data using SharedPreferences, Files, and SQLite database 1Data persistence.
Address Book App 1. Define styles   Specify a background for a TextView – res/drawable/textview_border.xml.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
SQLite (part deux) 1 CS440. Traditional Model View Controller (MVC) CS440 2.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
CHAPTER 9 File Storage Shared Preferences SQLite.
Android Storage MAY 2013 Hu.Cai. NAME OF PRESENTATION [CHANGE IN SLIDE MASTER] MONTH, YEAR [CHANGE IN SLIDE MASTER] Outline 1.Storage In General 2.SharedPreferences.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends.
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Database Programming Code Dissection. Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java.
1. 2 The Address Book app provides convenient access to contact information that’s stored in a SQLite database on the device. You can: scroll through.
CS371m - Mobile Computing Persistence - SQLite. 2 In case you have not taken 347: Data Management or worked with databases as part of a job, internship,
Content Providers.
Data Persistence Chapter 9. Objectives Learn about data storage methods Understand use of Shared Preferences Understand file-based storage and the differences.
CS499 – Mobile Application Development
Making content providers
3 A Guide to MySQL.
Data Storage: Part 3 (SQLite)
Content provider.
Android Content Providers & SQLite
Mobile Applications (Android Programming)
CS371m - Mobile Computing Persistence.
Android Application Data Storage 1.
Mobile Software Development for Android - I397
Mobile Application Development BSCS-7 Lecture # 18, 19
Mobile Applications (Android Programming)
Android Application SQLite 1.
Database JDBC Overview CS Programming Languages for Web Applications
Android Database using SQLite
Mobile Application Development Chapter 5 [Persistent Data in Android]
Mobile Computing With Android ACST Android Database Storage Part 2
Android Programming Lecture 7
CMPE419 Mobile Application Development
CS371m - Mobile Computing Persistence - SQLite.
CMPE419 Mobile Application Development
Department of School of Computing and Engineering
SQLLite and Android.
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

Data Persistence in Android 8.3.2013

Content Overview Preferences Using files Using databases Network connection

Storage Options Android provides several storage options for Private data Public data Depends on space requires .

Data Storage options Shared Preferences Files SQLite Databases Store private primitive data in key-value pairs. Files Store private data on the device memory. Store public data on the shared external storage. SQLite Databases Store structured data in a private database. Network Connection Store data on the web with your own network server.

Shared Preferences object It provides general framework for saving and retrieving To get Shared Preferences, use getSharedPreferences(String name) Use if you need multiple preference files (identified by name) getPreferences() Use if only one preferences file is needed To write values, call edit() to get SharedPreferences.Editor to be used when adding values to file

Shared Preferences

Files Its  possible  to  store  files  on  the  mobile  device  or  on  a   removable  storage    Current  application  folder  only. Exception  throws otherwise Modes:  MODE_PRIVATE,  MODE_WORLD_READABLE,   MODE_WORLD_WRITABLE .  Reading   –  openFileInput()   Writing   –  openFileOutput()    Standard  Java  streams  after  that

Files

SQLite Database Android Provides full support for SQLite To create a new SQLite database create a subclass of SQLiteOpenHelper   override the onCreate() method, execute a SQLite command to create tables in the database. 

SQLiteOpenHelper

Sqlite Database Database communication call getWritableDatabase() getReadableDatabase() It returns a SQLiteDatabase object for SQLite operations.

SQLite Database query() Use to execute SQLite queries, Every SQLite query returns a Cursor Cursor used to hold query result and read rows and columns. Cursor points to all the rows found by the query.

Querys

Create SQLite database Open the database according to the flags OPEN_READWRITE,OPEN_READONLY CREATE_IF_NECESSARY . Sets the locale of the database to the system's current locale. Parameters path to database file to open and/or create Factory an optional factory class that is called to instantiate a cursor when query is called, or null for default Flags to control database access mode Returns the newly opened database Throws SQLite Exception if the database cannot be opened

Create SQLite databse

Create SQLite databse

Create SQLite databse

warning Beware of sharing issues. can not access other people’s database resources (instead use Content Providers or SD resident DBs). An SD resident database requires the Manifest to include:

Method 2 SQLITE database where Default storage location in the devices ram is: "/data/data/<CURRENT_namespace>/databases/". “/data/data/cis493.sql1/databases/myfriendsDB”. Namespace Database

Open database Where: “myFriendsDB2”is the abbreviated file path. The prefix is assigned by Android as: /data/data/<appnamespace>/databases/myFriendsDB2. 2. MODE could be: MODE_PRIVATE, MODE_WORLD_READABLE, and MODE_WORLD_WRITEABLE. Meaningful for apps consisting of multiples activities. 3.Null refers to optional factory class parameter

Inserting Data Content Values are key/value pairs that are used when inserting/updating databases Each Content Value object corresponds to one row in a table ContentValues newValues = new ContentValues(); newValues.put("author", “xyz"); newValues.put("joke", "This is a joke"); myDb.insert("jokeTable",null,newValues);

Updating Data ContentValues updatedValues = new ContentValues(); updatedValues.put("joke", "This is a better joke"); myDb.update("jokeTable", updatedValues, "author=‘xyz'", //where clause null); //whereArgs

Querying Data with query() Cursor jokes = myDb.query("jokeTable", null, //columns null, //where clause null, //args if ? in where clause null, //groupBy null, //having null); //orderBy if (jokes.moveToFirst()) { do { String author = jokes.getString(1); String joke = jokes.getString(2); ((TextView)findViewById(R.id.hello)).setText(author + ": " + joke); } while(jokes.moveToNext()); }

Other Cursor Functions moveToPrevious getCount getColumnIndexOrThrow getColumnName getColumnNames moveToPosition getPosition

Deleting Data myDb.delete("jokeTable“, "author='David Janzen'“, null);