Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.

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.
컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android.
Introduction to Structured Query Language (SQL)
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 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.
CSCI 6962: Server-side Design and Programming
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
ASP.NET Programming with C# and SQL Server First Edition
ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
Lec 04 Content Providers Adapters CursorLoaders Advanced Debugging.
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.
Data Storage: Part 2 (File System). Internal Storage versus External Storage Internal storage − for private data –By default, files saved to the internal.
CODD’s 12 RULES OF RELATIONAL DATABASE
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
PROG Mobile Java Application Development PROG Mobile Java Application Development Memory and Memory Issues Data Storage.
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.
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.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
Chapter 17 Creating a Database.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Persistance Android. Adding Persistance SQL Refresher Understand how to create and migrate SQLLite database with android APIs. – Get all tasks – Add a.
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.
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.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
© 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.
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.
Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends.
Introduction to Database Programming with Python Gary Stewart
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.
Data Persistence Chapter 9. Objectives Learn about data storage methods Understand use of Shared Preferences Understand file-based storage and the differences.
Making content providers
Android Content Providers & SQLite
CS371m - Mobile Computing Persistence.
Android Application Data Storage 1.
SQLite in Android Landon Cox March 2, 2017.
Mobile Software Development for Android - I397
Android Application SQLite 1.
Android Database using SQLite
Mobile Application Development Chapter 5 [Persistent Data in Android]
Content Providers.
Android Storage.
Mobile Computing With Android ACST Android Database Storage Part 2
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Developing a Model-View-Controller Component for Joomla Part 3
SQLLite and Android.
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

Data Storage in Android Димитър Н. Димитров

Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science –Algorithms + Data Structures = ? Data as the basis for most of the successful Android apps

What options do we have? SharedPreferencesSharedPreference Internal storage (flash memory) External storage SQLite DB ContentProvider Internet/Network

SharedPreferences Persistent way to store key/value pairs Saved as XML in your application’s folder in /data/data Can be used for general settings of the application –See PreferenceActivityPreferenceActivity Can be obtained with different modes –MODE_PRIVATE –MODE_WORLD_READABLE –MODE_WORLD_WRITABLE android:sharedUserId + MODE_PRIVATEandroid:sharedUserId

SharedPreferences - 2 getSharedPreferences(String, int) SharedPreferences.Editor –obtain the editor by calling edit() to your preferences –write stuff with the editor –apply the changes by calling commit() to your editor Weird questions (WQ): –How safe is this? –When should I use this?

Internal Storage Data, saved on the internal storage of the device is located in your application’s folder in /data/data Like SharedPreferences, these files are removed, when the app is uninstalled What about getCacheDir()? YAFFS (> adb shell cat proc/yaffs) –read (very fast) –write (not very fast) –erase (very slow)

Internal Storage - 2 fileList()fileLis openFileOutput(String, int) openFileInput(String) deleteFile(String) getDir() WQ: What do you think are the return values of the above methods?

External Storage First, external storage is not always SD Card –Samsung Galaxy Tab has both internal_sd and external_sd If you rely on external storage, always –start with a check to getExternalStorageState()getExternalStorageState() –listen for broadcasts, regarding the state of the external storage (ACTION_MEDIA_EJECT, ACTION_MEDIA_REMOVED, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_BAD_REMOVAL, etc.)

External Storage - 2 With Android 2.2 (API Level 8), the ability to install applications on the external storage have been introduced –getExternalFilesDir(String) opens your application’s folder there –getExternalCacheDir() works similar to getCacheDir(), but the system doesn’t monitor it as much available space isn’t checked there isn’t application sandbox security Media scanner and pre-defined folders (API Level 8)

External Storage - 3 For Android 2.1-update1 (API Level 7) or below, use getExternalStorageDirectory() and the standard Java approach for creating and managing filesse getExternalStorageDirector Media scanner still recognizes specific folder names, but you have to create them manually “.nomedia” empty file - include in your folder, if you want the scanner to skip it –if you have the Android source, look at /external/opencore/mediascanner.cpp

SQLite What is SQLite? –Embedded RDBMS in 275 KB –public domain (whether this classifies as open-source is still an open debate) Android has full support for SQLite databases The sqlite3 tool is available for examining the contents of a table (.dump), the initial SQL CREATE statement (.schema) or executing queries dynamically (directly)sqlite3

SQLite - 2 Databases are saved in your application’s folder in /data/data To create and use SQLite database, use SQLiteOpenHelperSQLiteOpenHelper –use getReadableDatabase() or getWritableDatabase() –onCreate() of the helper is called (provide SQL CREATE statement here) –use some of the query() methods of SQLiteDatabase –Cursor is returned as a result of the queryCursor

SQLite - 3 Cursor can hold only about 1 MB, after which it has to use windowing (very slow). Be careful! For complex queries, use SQLiteQueryBuilder Using only SQLite can range from being very easy to being pretty hard –If you get to the pretty hard point, it’s good to use ContentProvider, even if you don’t have to share data WQ: Why doesn’t Android use the standard Java recommendation for abbreviations and acronyms for SQLite?

ContentProvider One of the fundamental components of Android applications Encapsulates data and provides common interface for it, independent from the implementation details The primary use of most ContentProviders is sharing data between multiple applications Generally, its interface is used via ContentResolver objects –Usually you access the same ContentProvider via different ContentResolvers from the different apps

ContentProvider - 2 The data model is similar to the RDB model –you can think of each record as represented by a row in a table with columns for each type of data One provider can contain multiple data sets (tables) Every data set in the provider has a unique URI –Different data sets have different URIs, for example the built-in Contacts provider has both android.provider.Contacts.Phones.CONTENT_URI and android.provider.Contacts.Photos.CONTENT_URI

ContentProvider - 3 Because of the similarities between ContentProviders and RDB models, very often SQLite databases are used together with ContentProvider Querying ContentProvider data can be done via either ContentResolver.query() or Activity.managedQuery(). –The difference is that the latter manages the lifecycle of the result Cursor. –Querying requires the URI of the provider, the fields that you want returned and the data types of these fields

ContentProvider - 4 Cursors can be used only for reading data Adding, modifying or deleting data is done via ContentResolver objects –adding and modifying are similar; use insert(Uri, ContentValues)insert(Uri, ContentValues) –for deleting use delete(Uri, String, String[])delete(Uri, String, String[]) WQ: What the arguments of delete stand for?

ContentProvider and REST Relation between REST HTTP methods and methods for using ContentProvider data –query() == GET –insert() == POST –update() == PUT –delete() == DELETE

Q & A

20 Resources and Links 7VDA#t=4m5shttp:// 7VDA#t=4m5s g2IQEhttp:// g2IQE ata/data-storage.htmlhttp://developer.android.com/guide/topics/d ata/data-storage.html