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.

Slides:



Advertisements
Similar presentations
Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Advertisements

Programming with Android: Data management
Bruce Scharlau, University of Aberdeen, 2010 Android Storage & SMS Apps Mobile Computing Unless otherwise stated, images are from android sdk See Unlocking.
Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from.
 data/data-storage.html#pref data/data-storage.html#pref 
Tracking & Login Data persistence User tracking.
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
NFC Inventory Android App
Data Persistence in Android
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.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
ContentProviders. SQLite Database SQLite is a software library that implements aself- contained, serverless,zero- configuration,transactionalSQL database.
Lec 04 Content Providers Adapters CursorLoaders Advanced Debugging.
Content providers Accessing shared data in a uniform way 1Content providers.
Cosc 5/4730 Android Content Providers and Intents.
Purdue Pride Joe Gutierrez Tung Ho Janam Jhaveri 4/7/2010Purdue Pride1.
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.
SQLite Supported by BlackBerry OS 5.0 Using SQLite.
Creating and using Persistent Data From before – Where does the data come from? – Why is it kept? – How is it used? Affects design and implementation choices.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
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.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
© 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.
Persistance Android. Adding Persistance SQL Refresher Understand how to create and migrate SQLLite database with android APIs. – Get all tasks – Add a.
Leveraging OO Features of IDS within the Java OO Framework of WebSphere Michael Chaney Technical Director ChainLink Networking Solutions, Inc.
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.
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.
Barnett Trzcinski September 13, Overview Stores a To-Do List Task, Due Date, Completed Persistent on Server Google App Engine.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
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.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
© 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.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
CHAPTER 9 File Storage Shared Preferences SQLite.
Exploring Networked Data and Data Stores Lesson 3.
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.
JDBC.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
Data in Windows 10 UWP Andy Wigley XML, JSON, SQLite or EF Core ?
Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends.
Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Data Persistence Chapter 9. Objectives Learn about data storage methods Understand use of Shared Preferences Understand file-based storage and the differences.
Android Content Providers & SQLite
Lecture 2: Android Concepts
Android Application Data Storage 1.
REST APIs and Android Presented by: James Simshaw
SQLite in Android Landon Cox March 2, 2017.
Android Application SQLite 1.
Mobile Application Development Chapter 5 [Persistent Data in Android]
CIS 136 Building Mobile Apps
Android Storage.
CIS 136 Building Mobile Apps
Mobile Computing With Android ACST 4550 Android Database Storage
PHP Forms and Databases.
Department of School of Computing and Engineering
SQLLite and Android.
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

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. We can send data across the network to a service. We can use a database.

Preference files are a light-weight option We can put data into a preferences file. Call Context.getSharedPreferences() to read and write values as key-value pairs. Use Activity.getPreferences() with no name to keep them private to the calling activity These are not sharable across applications, unless you expose them as a ‘content provider’.

We can write larger data to file You can either write to a new file, or to a pre- included file under res/raw/mydata To can read data from a file, call Context.openFileInput() and pass it the local name and path of the file. It returns a standard Java FileInputStream object. To write to a file, call Context.openFileOutput() with the name and path. It returns a FileOutputStream object. You can only access files available to the application

We can place data elsewhere on the network Use a web service to store data elsewhere. Can make this automatic, or at user discretion. (twitter apps, or photo capture)

We can also persist data to a db Android API uses the built-in SQLite db. Each db is private to the application. In principle you could expose the data, if you expose the application as a content provider. All databases, SQLite and others, are stored on the device in /data/data/package_name/databases.

Android Notepad tutorial uses database Useful db helper class for access and crud details

Context Menu is special Acquire context menu by holding down selection key, which then pops up context menu

Unlocking Android db example covers more complex example Stores locations to database within application as objects

Android app uses db helper classes with sql Bruce Scharlau, University of Aberdeen, 2009 public static class Location { public long id; public long lastalert; public int alertenabled; public String zip; // include city and region because geocode is expensive public String city; public String region; public Location() { } public Location(final long id, final long lastalert, final int alertenabled, final String zip, final String city, final String region) { this.id = id; this.lastalert = lastalert; this.alertenabled = alertenabled; this.zip = zip; this.city = city; this.region = region; } Part of DBHelper class showing Location object Class also holds crud details to map object to sql

Android app maps objects to sql for ease Bruce Scharlau, University of Aberdeen, 2009 public void insert(final Location location) { ContentValues values = new ContentValues(); values.put("zip", location.zip); values.put("city", location.city); values.put("region", location.region); values.put("lastalert", location.lastalert); values.put("alertenabled", location.alertenabled); this.db.insert(DBHelper.DB_TABLE, null, values); } public void update(final Location location) { ContentValues values = new ContentValues(); values.put("zip", location.zip); values.put("city", location.city); values.put("region", location.region); values.put("lastalert", location.lastalert); values.put("alertenabled", location.alertenabled); this.db.update(DBHelper.DB_TABLE, values, "_id=" + location.id, null); } Mapping makes coding easier

SQLite provides advanced db features There is transaction support You can use prepared statements based on java.sql and set items as have done before – faster and more secure You have a cursor to keep track of location within a resultset

Can map objects to db Can read items from network as xml and convert to objects, which map to db Enables off network use and can sync later when connected Might be pushing limits of device though with extra classes and memory usage

Summary Can use preferences for each app Can write/read files as with Java Can persist/read items over network (when available) Can use SQLite one db per app