The Basis of Data. Steven R. Bagley

Similar documents
Mobile and Ubiquitous Computing: Android Programming (part 4)

Android Programming Lecture 16 11/4/2011

Android: Data Storage

CS371m - Mobile Computing. Persistence

SharedPreference. <map> <int name="access_count" value="3" /> </map>

Android Components. Android Smartphone Programming. Matthias Keil. University of Freiburg

How-to s and presentations. Be prepared to demo them in class. ons

Android Components Android Smartphone Programming. Outline University of Freiburg. Data Storage Database University of Freiburg. Notizen.

Android Programming Lecture 15 11/2/2011

MOBILE APPLICATIONS PROGRAMMING

CS378 -Mobile Computing. Persistence

07. Data Storage

Spring Lecture 5 Lecturer: Omid Jafarinezhad

CSCU9YH: Development with Android

EMBEDDED SYSTEMS PROGRAMMING SQLite

Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza. Data persistence

Single Application Persistent Data Storage. CS 282 Principles of Operating Systems II Systems Programming for Android

Mobile Application Development Android

Mobile Application Development Android

Data storage and exchange in Android

SQLite. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases. What is a Database Server. Advantages of SQLite

Mediensystemen mit Android

App Development for Smart Devices. Lec #5: Content Provider

CS371m - Mobile Computing. Persistence - SQLite

Mobile Application Development Android

CS378 -Mobile Computing. Persistence -SQLite

Database Development In Android Applications

SQLite Database. References. Overview. Structured Databases

Presentation Outline 10/16/2016

SAVING SIMPLE APPLICATION DATA

Android File & Storage

Sri Vidya College of Engineering & Technology Question Bank

CS371m - Mobile Computing. Content Providers And Content Resolvers

Object-Oriented Databases Object-Relational Mappings and Frameworks. Alexandre de Spindler Department of Computer Science

Data Structures. 03 Streams & File I/O

Automatically persisted among application sessions

1. Implementation of Inheritance with objects, methods. 2. Implementing Interface in a simple java class. 3. To create java class with polymorphism

SharedPreferences Internal Storage External Storage SQLite databases

Writing Efficient Drive Apps for Android. Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations

Content Provider. Introduction 01/03/2016. Session objectives. Content providers. Android programming course. Introduction. Built-in Content Provider

File Operations in Java. File handling in java enables to read data from and write data to files

ADF Mobile Code Corner

Software Engineering Large Practical: Preferences, storage, and testing


Mr. Pritesh N. Patel Assistant Professor MCA ISTAR, V. V. Nagar ANDROID DATABASE TUTORIAL

How to access your database from the development environment. Marco Ronchetti Università degli Studi di Trento

Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

OFFLINE MODE OF ANDROID

Mobile Programming Lecture 10. ContentProviders

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2

Android writing files to the external storage device

JAVA MOCK TEST JAVA MOCK TEST II

Introduction to Programming Using Java (98-388)

An Android Studio SQLite Database Tutorial

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

ANALYZING THE MOST COMMON PERFORMANCE AND MEMORY PROBLEMS IN JAVA. 18 October 2017

Syllabus- Java + Android. Java Fundamentals

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

Mobile Computing Practice # 2d Android Applications Local DB

CS 403X Mobile and Ubiquitous Computing Lecture 5: Web Services, Broadcast Receivers, Tracking Location, SQLite Databases Emmanuel Agu

Files and IO, Streams. JAVA Standard Edition

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

CS 4330/5390: Mobile Application Development Exam 1

Application Fundamentals

Experiment No: Group B_4

Software Practice 3 Today s lecture Today s Task

Special error return Constructors do not have a return value What if method uses the full range of the return type?

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading.

More on Objects in JAVA TM

Android.database.sqlite.sqliteexception Error Code 14 Unable To Open Database File

Tiers (or layers) Separation of concerns

Java Application Development

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

Firebase Realtime Database. Landon Cox April 6, 2017

CS Android. Vitaly Shmatikov

Software Engineering Large Practical: Storage, Settings and Layouts. Stephen Gilmore School of Informatics October 27, 2017

PIC 20A Streams and I/O

BLAISE NG DATA MANAGEMENT

Software 1 with Java. Recitation No. 7 (Java IO) May 29,

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

Java Training Center - Android Application Development

Programming Assignment Comma Separated Values Reader Page 1

M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 1

Software 1. Java I/O

CS193j, Stanford Handout #26. Files and Streams

Android framework. How to use it and extend it

DEVELOPMENT OF PUBLIC FACILITY AND HOUSEHOLD LOCATOR TOOL USING MOBILE GIS AND ANDROID TECHNOLOGY

Autonomous Configuration UI

Learn about Android Content Providers and SQLite

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Software 1 with Java. Recitation No. 9 (Java IO) December 10,

Programming Languages and Techniques (CIS120)

Java Support for developing TCP Network Based Programs

1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java

CS 101 Fall 2006 Midterm 1 Name: ID:

needs to be reliable, easy to change, retarget efficiency is secondary implemented as interpreter, with virtual machine

OBJECT ORİENTATİON ENCAPSULATİON

Configuring the Android Manifest File

CS Programming I: File Input / Output

Transcription:

The Basis of Data Steven R. Bagley

So far How to create a UI View defined in XML Java-based Activity as the Controller Services Long running processes Intents used to send messages between things asynchronously

Data Apps generally store, process and display data Normally stored in files Android doesn t have a traditional file system Why not? Security mainly Put also enables the app to be cleanly removed Storage at a premium on the device

Data storage on Android Shared Preferences File-based storage Internal Data Storage External Data Storage SQLite Database Network

File access Android uses the standard Java I/O classes to access files File, InputStream, OutputStream, etc However, obtained in a different way Show s the power of OO abstraction same interface but different access mechanism

Internal Data Storage Internal Data storage is private to the app Other apps (and the user) cannot access it Removed on uninstall Data is stored in Files (Access Without permission)

Accessing Internal Storage Two methods are used to access files on internal storage Context.openFileOutput(String name, int mode) Returns a FileOutputStream Context.openFileInput(String name) Returns a FileInputStream Don t forget to catch IOExceptions Go give a demo of how we can access this

Cache Files Android provides a standard place to store (small) cache files Use getcachedir() to get a File for the directory Still need to manage the files yourself

External Data Storage Every Android device provides externallyaccessible storage, e.g. SD card Can be mounted externally (and/or disconnected) Before accessing files you need to check the state of external storage Files deleted when app uninstalled

External Data Storage Check state with Environment.getExternalStorageState() Returns a String containing the details Compare with the constants: Environment.MEDIA_MOUNTED Environment.MEDIA_MOUNTED_READ_ONLY To check the state

Accessing External Storage Use Context.getExternalFilesDir(String type) to obtain a File for the directory If you pass a type (it can be null) then returns a sub-directory of appropriate type Used to enable the Media scanner to categorize material Use File object returned to createnewfile() DIRECTORY_MUSIC DIRECTORY_RINGTONES etc Go modify demo

Structured Data Often the data we are storing is structured And we want to query it based on that structure Could store this in a file and write our own routines to access it Normally, we d use a database to store it E.g Address Book, music library

Android Databases Android comes with local database Complete with the ability to run SQL queries Each app s databases are local to it

Android and SQLite Uses SQLite Public Domain software library A software library that implements a selfcontained, serverless, zero-configuration, transactional SQL database engine. Most widely deployed software engine on the planet

Android and SQLite Wrapped up in two main classes Database represented by SQLiteDatabase Lets us run SQL queries on the database Also provides SQLiteOpenHelper to help create the database

Creating a DB SQLiteOpenHelper manages database creation and upgrades between versions Create a subclass of it Override oncreate to provide the code to create the database Using SQL CREATE TABLE Handled automatically See example and documentation for how to call superclass

Accessing the DB Create an instance of our SQLiteOpenHelper subclass Obtain reference to SQLiteDatabase using: getreadabledatabase() getwriteabledatabase() Return the same object, unless memory is low and can only open the DB readonly

Querying the DB SQLiteDatabase has many methods void execsql() used to run SQL queries that don t return anything More useful are query() and rawquery() These return a Cursor object that can be used to access the data

Querying the DB Cursor rawquery(string sql, String[] selectionargs) processes SQL query in sql SQL has to be parsed so there is also query() where the SQL is exploded into separate strings Cursor query(string table, String[] columns, String selection, String[] selectionargs, String groupby, String having, String orderby)

Cursor object Pretty self explanatory object Enables you to step over all the rows returned by a query Has a close() method to close the query when you are finished (don t wait for it to be garbage collected)

Methods int getcolumncount() int getcolumnindex(string name) String getcolumnname(int columnindex) int getcount() Description Return the total number of columns Return the index for the column named name (or -1) Return the name of the column Return the number of rows

Methods byte[] getblob(int columnindex) float getfloat(int columnindex) int getint(int index) int getstring(int index) Description Return value of the column as a byte array Return value of the column as a float Return the value of column as an int Return the value of column as a String And so on, you name it there is a method for every type Returns data from the current row

Methods boolean isfirst() boolean islast() boolean move(int offset) boolean movetofirst() boolean movetolast() boolean movetonext() Description Is this the first/last row in the result? Move the cursor relative to the current position, offset places Guess moves to the next row, false if past the end of the result Returns data from the current row

Content Providers Access to data is restricted to the app that owns it If we want other apps to access our data, or we want to access other apps data Then we need to provide or make use of a ContentProvider