Data Storage Methods in Android
|
|
- April Booth
- 5 years ago
- Views:
Transcription
1 Data Storage Methods in Android
2 Data Storage Applica4ons o5en need to use some type of data storage for persistent data. The Android framework offers different data storage op4ons: Shared preferences: Useful for storing primi4ve data in key- value pairs Lightweight usage, such as saving applica4on seengs, UI state Flat file based storage: Storing private data in device memory Storing public data on external storage, e.g., SD card Uses standard Java file storage access methods: InputFileStream and OutputFileStream SQLite database: Provides a means of storing structured data in a private database You can also store your data on a network server and access it using the network COMP 355 (Muppala) Data Storage 2
3 Shared Preferences COMP 355 (Muppala) Data Storage 3
4 Shared Preferences This class provides a general framework that allows saving and retrieving of persistent key- value pairs of primi4ve data Typical usage of SharedPreferences is for saving applica4on seengs such as user seengs, theme, login informa4on such as username and password, auto login flag, remember- user flag etc. The shared preferences informa4on is stored in an XML file on the device Typically in /data/data/<your applica4on s package name>/ shared_prefs SharedPreferences can be associated with the en4re applica4on, or to a specific ac4vity COMP 355 (Muppala) Data Storage 4
5 Shared Preferences Use the getsharedpreferences() method to get access to the shared preferences Example: SharedPreferences prefs = this.getsharedpreferences( myprefs, MODE_PRIVATE); If the preferences XML file exists, it is opened, otherwise it is created To control access permissions to the file: MODE_PRIVATE: private only to the applica4on MODE_WORLD_READABLE: all applica4ons can read the XML file MODE_WORLD_WRITEABLE: all applica4ons can write the XML file If you are using SharedPreferences for a specific ac4vity, then use getpreferences() method No need to specify the name of the preferences file COMP 355 (Muppala) Data Storage 5
6 Shared Preferences To add shared preferences, first an Editor object is needed: Editor prefseditor = prefs.edit(); Then, use the put() method to add the key- value pairs: prefseditor.putstring( username, user1 ); prefseditor.putstring( password, pass1234 ); prefseditor.putint( 4mes- login,1); prefseditor.commit(); To retrieve shared preferences data: String username = prefseditor.getstring( username, ); String password = prefseditor.getstring( password, ); COMP 355 (Muppala) Data Storage 6
7 User Preferences and PreferenceAc4vity SeEng user preferences for an applica4on is supported in Android through the PreferenceAc4vity class Provides an ac4vity framework to create user preferences Preferences are automa4cally persisted using shared preferences To add preferences to your applica4on: Create a preferences.xml file in the /res/xml directory: Create a new ac4vity extending PreferenceAc4vity and reading in the default preferences from the xml file above Add the ac4vity to your AndroidManifest.xml file Invoke your preference ac4vity from another ac4vity COMP 355 (Muppala) Data Storage 7
8 Flat File Storage COMP 355 (Muppala) Data Storage 8
9 Flat File Storage Files are used to store large amount of data Generally not recommended to use files Use I/O interfaces provided by java.io.* libraries to read/write files. Only local files can be accessed. Advantage: can store large amount of data. Disadvantage: Upda4ng files or changing their format may lead to massive coding work. COMP 355 (Muppala) Data Storage 9
10 File Opera4on (Read) Read file Use Context.openFileInput(String name) to open a private input file stream related to a program Throw FileNotFoundExcep4on when the file does not exist. FileInputStream in = this.openfileinput( rt.txt");//open file rt.txt" in.close();//close input stream COMP 355 (Muppala) Data Storage 10
11 File Opera4on (Write) Write File Use Context.openFileOutput(String name,int mode) to open a private output file stream related to a program The file will be created if it does not exist. Output stream can be opened in append mode, which means new data will be appended to end of the file. String mystring = Hello, World! ; FileOutputStream ouoile = this.openfileoutput( myfile.txt",mode_append); //Open and write in myfile.txt, using append mode. Ouoile.write(mystring.getBytes()); ouoile.close();//close output stream Also possible to use: MODE_PRIVATE, MODE_WORLD_READABLE MODE_WORLD_WRITEABLE COMP 355 (Muppala) Data Storage 11
12 Read Sta4c Files Sta4c files that are included in the applica4on are created in the /res/raw directory Read- only sta4c files Use Resources.openRawResource(R.raw.mydatafile) to open sta4c files. InputStream myfile = getresources().openrawresource(r.raw.myfilename); //Get context resource myfile.close(); //Close input stream COMP 355 (Muppala) Data Storage 12
13 External Storage Every Android- compa4ble device supports a shared "external storage" that you can use to save files Removable storage media (such as an SD card) Internal (non- removable) storage Files saved to the external storage are world- readable and can be modified by the user when they enable USB mass storage to transfer files on a computer COMP 355 (Muppala) Data Storage 13
14 External Storage Must check whether external storage is available first by calling getexternalstoragestate() Also check whether it allows read/write before reading/wri4ng on it Example: if(environment.getexternalstoragestate().equals(environment.media_mounted)){ File sdcarddir = Environment.getExternalFilesDir(null);//Get SD Card directory File outfile = new File(sdCardDir, example.txt ); FileOutputStream outstream = new FileOutputStream(outFile); outstream.write( Hello, world!".getbytes()); outstream.close(); } These files are private to the applica4on and will be removed when the applica4on is uninstalled getexternalfilesdir() takes a parameter such as DIRECTORY_MUSIC, DIRECTORY_RINGTONES etc., to open specific type of subdirectories COMP 355 (Muppala) Data Storage 14
15 External Storage For public shared directories, use getexternalstoragepublicdirectory() For cache files, use getexternalcachedir() All these are applicable for API level 8 or above For API level 7 or below, use the method: getexternalstoragedirectory() private files stored in /Android/data/<package_name>/files/ Cache files stored in /Android/data/<package_name>/cache/ COMP 355 (Muppala) Data Storage 15
16 SQLite Databases COMP 355 (Muppala) Data Storage 16
17 SQLite Database Android applica4ons can have applica4on databases powered by SQLite Lightweight and file- based, ideal for mobile devices Databases are private for the applica4on that creates them Databases should not be used to store files SQLite is a light weight database Atomic Stable Independent Enduring Only several kilobytes Only partly support some SQL commands such as ALTER, TABLE. SQLite is included as part of Android s so5ware stack More info about SQLite at hup:// COMP 355 (Muppala) Data Storage 17
18 SQLite Databases Steps for using SQLite databases: 1. Create a database 2. Open the database 3. Create a table 4. Create and insert interface for datasets 5. Create a query interface for datasets 6. Close the database Good prac4ce to create a Database Adapter class to simplify your database interac4ons We will use the SQLite database defined in the notebook tutorial as an example COMP 355 (Muppala) Data Storage 18
19 SQLite Example: Notebook Tutorial public class NotesDbAdapter { public sta3c final String KEY_TITLE = "+tle"; public sta3c final String KEY_BODY = "body"; public sta3c final String KEY_ROWID = "_id"; private sta3c final String TAG = "NotesDbAdapter"; private DatabaseHelper mdbhelper; private SQLiteDatabase mdb; /** * Database crea4on sql statement */ private sta3c final String DATABASE_CREATE = "create table notes (_id integer primary key autoincrement, " + "4tle text not null, body text not null);"; private sta3c final String DATABASE_NAME = "data"; private sta3c final String DATABASE_TABLE = "notes"; private sta3c final int DATABASE_VERSION = 2; private final Context mctx; COMP 355 (Muppala) Data Storage 19
20 SQLiteOpenHelper Class Abstract class for implemen4ng a best prac4ce pauern for crea4ng, opening and upgrading databases To create a SQLite database, the recommended approach is to create a subclass of SQLiteOpenHelper class Then override its oncreate() method Then execute a SQLite command to create tables in the database Use the onupgrade() method to handle upgrade of the database A simple way would be to drop an exis4ng table and replace with a new defeni4on Beuer to migrate exis4ng data into a new table Then use an instance of the helper class to manage opening or upgrading the database If the database doesn t exist, the helper will create one by calling its oncreate() handler If the database version has changed, it will upgrade by calling the onupgrade() handler COMP 355 (Muppala) Data Storage 20
21 SQLite Example: Notebook Tutorial private sta3c class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); public void oncreate(sqlitedatabase db) { } db.execsql(database_create); public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { Log.w(TAG, "Upgrading database from version " + oldversion + " to " + newversion + ", which will destroy all old data"); db.execsql("drop TABLE IF EXISTS notes"); oncreate(db); } COMP 355 (Muppala) Data Storage 21
22 SQLite Example: Notebook Tutorial public NotesDbAdapter(Context ctx) { this.mctx = ctx; } public NotesDbAdapter open() throws SQLExcep3on { mdbhelper = new DatabaseHelper(mCtx); mdb = mdbhelper.getwritabledatabase(); return this; } public void close() { mdbhelper.close(); } COMP 355 (Muppala) Data Storage 22
23 SQLite Databases ContentValues() objects used to hold rows to be inserted into the database Example: public long createnote(string 3tle, String body) { ContentValues ini4alvalues = new ContentValues(); ini4alvalues.put(key_title, Mtle); ini4alvalues.put(key_body, body); } return mdb.insert(database_table, null, ini+alvalues); public boolean deletenote(long rowid) { return mdb.delete(database_table, KEY_ROWID + "=" + rowid, null) > 0; } public boolean updatenote(long rowid, String 3tle, String body) { ContentValues args = new ContentValues(); args.put(key_title, Mtle); args.put(key_body, body); } return mdb.update(database_table, args, KEY_ROWID + "=" + rowid, null) > 0; COMP 355 (Muppala) Data Storage 23
24 SQLite Databases Database queries are returned as Cursor objects Pointers to the resul4ng sets within the underlying data Cursor class provides several methods: movetofirst, movetonext, movetoprevious, movetoposi4on used to move to a row getcount to get the number of rows in the cursor getposi4on to get the current row posi4on getcolumnname, getcolumnnames, getcolumnindexorthrow to get info on columns startmanagingcursor and stopmanagingcursor methods used to integrate cursor life4me into the ac4vity s life4me COMP 355 (Muppala) Data Storage 24
25 SQLite Example: Notebook Tutorial public Cursor fetchallnotes() { return mdb.query(database_table, new String[] {KEY_ROWID, KEY_TITLE, KEY_BODY}, null, null, null, null, null); } public Cursor fetchnote(long rowid) throws SQLExcep3on { } Cursor mcursor = mdb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowid, null, null, null, null, null); if (mcursor!= null) { mcursor.movetofirst(); } return mcursor; COMP 355 (Muppala) Data Storage 25
26 SQLite Example: Notebook Tutorial Within the main ac4vity, cursors returned by the Dbadapter are used as follows: private void filldata() { Cursor notescursor = mdbhelper.fetchallnotes(); startmanagingcursor(notescursor); // Create an array to specify the fields we want to display in the list (only TITLE) String[] from = new String[]{NotesDbAdapter.KEY_TITLE}; // and an array of the fields we want to bind those fields to (in this case just text1) int[] to = new int[]{r.id.text1}; } // Now create a simple cursor adapter and set it to display SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, notescursor, from, to); setlistadapter(notes); COMP 355 (Muppala) Data Storage 26
27 Content Providers COMP 355 (Muppala) Data Storage 27
28 Content Providers Store and retrieve data and make it available to all applica4ons Only way to share data across applica4ons Standard content providers part of Android: Common data types (audio, video, images, personal contact informa4on) Applica4ons can create their own content providers to make their data public Alterna4vely add the data to an exis4ng provider Implement a common interface for querying the provider, adding, altering and dele4ng data Actual storage of data is up to the designer Provides a clean separa4on between the applica4on layer and data layer COMP 355 (Muppala) Data Storage 28
29 Accessing Content Applica4ons access the content through a ContentResolver instance ContentResolver allows querying, inser4ng, dele4ng and upda4ng data from the content provider ContentResolver cr = getcontentresolver(); cr.query(people.content_uri, null, null, null, null); //querying contacts ContentValues newvalues = new ContentValues(); cr.insert(people.content_uri, newvalues); cr.delete(people.content_uri, null, null); //delete all contacts COMP 355 (Muppala) Data Storage 29
30 Content Providers Content providers expose their data as a simple table on a database model Each row is a record and each column is data of a par4cular type and meaning Queries return cursor objects Each content provider exposes a public URI that uniquely iden4fies its data set Separate URI for each data set under the control of the provider URIs start with content:// Typical format: Content://<package name>.provider.<custom provider name>/<datapath> COMP 355 (Muppala) Data Storage 30
31 Content Providers: Query You need three pieces of informa4on to query a content provider: The URI that iden4fies the provider The names of the data fields you want to receive The data types for those fields If you're querying a par4cular record, you also need the ID for that record Example: import android.provider.contacts.people; import android.content.contenturis; import android.net.uri; import android.database.cursor; // Use the ContentUris method to produce the base URI for the contact with _ID == 23. Uri myperson = ContentUris.withAppendedId(People.CONTENT_URI, 23); // Alterna4vely, use the Uri method to produce the base URI. // It takes a string rather than an integer. Uri myperson = Uri.withAppendedPath(People.CONTENT_URI, "23"); // Then query for this specific record: Cursor cur = managedquery(myperson, null, null, null, null); COMP 355 (Muppala) Data Storage 31
32 Content Providers: Query import android.provider.contacts.people; import android.database.cursor; // Form an array specifying which columns to return. String[] projec4on = new String[] { People._ID, People._COUNT, People.NAME, People.NUMBER }; // Get the base URI for the People table in the Contacts content provider. Uri contacts = People.CONTENT_URI; // Make the query. Cursor managedcursor = managedquery(contacts, projec4on, // Which columns to return null, // Which rows to return (all rows) null, // Selec4on arguments (none) // Put the results in ascending order by name People.NAME + " ASC"); COMP 355 (Muppala) Data Storage 32
33 Content Providers: Query Retrieving the data: import android.provider.contacts.people; private void getcolumndata(cursor cur){ if (cur.movetofirst()) { String name; String phonenumber; int namecolumn = cur.getcolumnindex(people.name); int phonecolumn = cur.getcolumnindex(people.number); String imagepath; do { // Get the field values name = cur.getstring(namecolumn); phonenumber = cur.getstring(phonecolumn); // Do something with the values.... } while (cur.movetonext()); } } COMP 355 (Muppala) Data Storage 33
34 Content Providers: Modifying Data Data kept by a content provider can be modified by: Adding new records Adding new values to exis4ng records Batch upda4ng exis4ng records Dele4ng records All accomplished using ContentResolver methods Use ContentValues() to add or update data COMP 355 (Muppala) Data Storage 34
35 Content Providers: Adding Data Adding new records: import android.provider.contacts.people; import android.content.contentresolver; import android.content.contentvalues; ContentValues values = new ContentValues(); // Add Abraham Lincoln to contacts and make him a favorite. values.put(people.name, "Abraham Lincoln"); // 1 = the new contact is added to favorites // 0 = the new contact is not added to favorites values.put(people.starred, 1); Uri uri = getcontentresolver().insert(people.content_uri, values); COMP 355 (Muppala) Data Storage 35
36 Content Providers: Adding Data Adding new values: Uri phoneuri = null; Uri uri = null; phoneuri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY); values.clear(); values.put(people.phones.type, People.Phones.TYPE_MOBILE); values.put(people.phones.number, " "); getcontentresolver().insert(phoneuri, values); // Now add an address in the same way. uri = Uri.withAppendedPath(uri, People.ContactMethods.CONTENT_DIRECTORY); values.clear(); // ContactMethods.KIND is used to dis4nguish different kinds of // contact methods, such as , IM, etc. values.put(people.contactmethods.kind, Contacts.KIND_ ); values.put(people.contactmethods.data, "test@example.com"); values.put(people.contactmethods.type, People.ContactMethods.TYPE_HOME); getcontentresolver().insert( uri, values); COMP 355 (Muppala) Data Storage 36
37 Content Providers Use ContentResolver.update() to batch update fields Use ContentResolver.delete() to delete: A specific row Mul4ple rows, by calling the method with the URI of the type of record to delete and an SQL WHERE clause defining which rows to delete COMP 355 (Muppala) Data Storage 37
38 Crea4ng Content Providers To create a content provider, you must: Set up a system for storing the data. Most content providers store their data using Android's file storage methods or SQLite databases, but you can store your data any way you want. Extend the ContentProvider class to provide access to your data Declare the content provider in the manifest file for your applica4on (AndroidManifest.xml) COMP 355 (Muppala) Data Storage 38
39 Crea4ng Content Providers Extending the ContentProvider class will require: Implemen4ng the following methods: query(), insert(), update(), delete(), gettype(), oncreate() Make sure that these implementa4ons are thread- safe as they may be called from several ContentResolver objects in several different processes and threads In addi4on, you need to: Declare a public sta4c final URI named CONTENT_URI Define the column names that the content provider will return to clients Carefully document the data type of each column COMP 355 (Muppala) Data Storage 39
40 Crea4ng Content Providers You need to declare the content provider in the Manifest file: Example: <provider android:name="com.example.autos.autoinfoprovider" android:authori4es="com.example.autos.autoinfoprovider"... /> </provider> COMP 355 (Muppala) Data Storage 40
CSCU9YH: Development with Android
: Development with Android Computing Science and Mathematics University of Stirling Data Storage and Exchange 1 Preferences: Data Storage Options a lightweight mechanism to store and retrieve keyvalue
More informationMobile Application Development Android
Mobile Application Development Android Lecture 3 MTAT.03.262 Satish Srirama satish.srirama@ut.ee Android Lecture 2 - recap Views and Layouts Events Basic application components Activities Intents 9/15/2014
More informationApp Development for Smart Devices. Lec #5: Content Provider
App Development for Smart Devices CS 495/595 - Fall 2011 Lec #5: Content Provider Tamer Nadeem Dept. of Computer Science Some slides adapted from Jussi Pohjolainen and Bob Kinney Objective Data Storage
More informationMobile Application Development Android
Mobile Application Development Android Lecture 3 MTAT.03.262 Satish Srirama satish.srirama@ut.ee Android Lecture 2 -recap Views and Layouts Events Basic application components Activities Intents BroadcastReceivers
More informationHow-to s and presentations. Be prepared to demo them in class. https://sites.google.com/site/androidhowto/presentati ons
Upcoming Assignments Readings: Chapter 6 by today Lab 3 due today (complete survey) Lab 4 will be available Friday (due February 5) Friday Quiz in Blackboard 2:10-3pm (Furlough) Vertical Prototype due
More informationAndroid: Data Storage
Android: Data Storage F. Mallet Frederic.Mallet@unice.fr Université Nice Sophia Antipolis Outline Data Storage Shared Preferences Internal Storage External Storage SQLite Databases Network Connection F.
More information07. Data Storage
07. Data Storage 22.03.2018 1 Agenda Data storage options How to store data in key-value pairs How to store structured data in a relational database 2 Data Storage Options Shared Preferences Store private
More informationSQLite Database. References. Overview. Structured Databases
SQLite Database References Android Developers Article https://developer.android.com/training/basics/data-storage/databases.html Android SQLite Package Reference https://developer.android.com/reference/android/database/sqlite/package-summary.html
More informationThe Basis of Data. Steven R. Bagley
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
More informationMobile Application Development Android
Mobile Application Development Android Lecture 3 MTAT.03.262 Satish Srirama satish.srirama@ut.ee Android Lecture 2 - recap Views and Layouts Events Basic application components Activities Intents 9/22/2017
More informationDatabase Development In Android Applications
ITU- FAO- DOA- TRCSL Training on Innovation & Application Development for E- Agriculture Database Development In Android Applications 11 th - 15 th December 2017 Peradeniya, Sri Lanka Shahryar Khan & Imran
More informationEng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza. Data persistence
Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza Data persistence Shared preferences A method to store primitive data in android as key-value pairs, these saved data will
More informationMobile and Ubiquitous Computing: Android Programming (part 4)
Mobile and Ubiquitous Computing: Android Programming (part 4) Master studies, Winter 2015/2016 Dr Veljko Pejović Veljko.Pejovic@fri.uni-lj.si Examples from: Mobile and Ubiquitous Computing Jo Vermeulen,
More informationCS371m - Mobile Computing. Persistence
CS371m - Mobile Computing Persistence Storing Data Multiple options for storing data associated with apps Shared Preferences Internal Storage device memory External Storage SQLite Database Network Connection
More informationAn Android Studio SQLite Database Tutorial
An Android Studio SQLite Database Tutorial Previous Table of Contents Next An Android Studio TableLayout and TableRow Tutorial Understanding Android Content Providers in Android Studio Purchase the fully
More informationSharedPreferences Internal Storage External Storage SQLite databases
SharedPreferences Internal Storage External Storage SQLite databases Use when you want to store small amounts of primitive data A persistent map that holds key-value pairs of simple data types Automatically
More informationSpring Lecture 5 Lecturer: Omid Jafarinezhad
Mobile Programming Sharif University of Technology Spring 2016 - Lecture 5 Lecturer: Omid Jafarinezhad Storage Options Android provides several options for you to save persistent application data. The
More informationMobile Programming Lecture 10. ContentProviders
Mobile Programming Lecture 10 ContentProviders Lecture 9 Review In creating a bound service, why would you choose to use a Messenger over extending Binder? What are the differences between using GPS provider
More informationData storage overview SQLite databases
http://www.android.com/ Data storage overview SQLite databases Data storage overview Assets (assets) and Resources (res/raw) Private data installed with the application (read-only) Use the android.content.res.xxx
More informationData storage and exchange in Android
Mobile App Development 1 Overview 2 3 SQLite Overview Implementation 4 Overview Methods to implement URI like SQL 5 Internal storage External storage Overview 1 Overview 2 3 SQLite Overview Implementation
More informationSAVING SIMPLE APPLICATION DATA
1 DATA PERSISTENCE OBJECTIVES In this chapter, you will learn how to persist data in your Android applications. Persisting data is an important topic in application development, as users typically expect
More informationMobile Computing Practice # 2d Android Applications Local DB
Mobile Computing Practice # 2d Android Applications Local DB In this installment we will add persistent storage to the restaurants application. For that, we will create a database with a table for holding
More informationContent Provider. Introduction 01/03/2016. Session objectives. Content providers. Android programming course. Introduction. Built-in Content Provider
Android programming course Session objectives Introduction Built-in Custom By Võ Văn Hải Faculty of Information Technologies 2 Content providers Introduction Content providers manage access to a structured
More informationData Storage, ContentProvider
안드로이드애플리케이션교육자료 5 Data Storage, ContentProvider www.kandroid.org 운영자 : 양정수 (yangjeongsoo@gmail.com), 닉네임 : 들풀 5. Java 클래스에매핑된 XML 레이아웃파일기반의사용자인터페이스 안드로이드는사용자인터페이스를구현하기위한도구로 HTML과같이가독성이있는 XML 기반의레이아웃파일을사용한다.
More informationCS371m - Mobile Computing. Persistence - SQLite
CS371m - Mobile Computing Persistence - SQLite In case you have not taken 347: Data Management or worked with databases as part of a job, internship, or project: 2 Databases RDBMS relational data base
More informationMediensystemen mit Android
LFE Medieninformatik i ik Prof. Dr. Heinrich i Hußmann (Dozent), Alexander De Luca, Gregor Broll, Max-Emanuel Maurer (supervisors) Praktikum Entwicklung von Mediensystemen mit Android Storing, Retrieving
More informationSingle Application Persistent Data Storage. CS 282 Principles of Operating Systems II Systems Programming for Android
Single Application Persistent Data Storage CS 282 Principles of Operating Systems II Systems Programming for Android Android offers several ways to store data Files SQLite database SharedPreferences Android
More informationSQLite. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases. What is a Database Server. Advantages of SQLite
SQLite 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases Dr Dimitris C. Dracopoulos SQLite is a tiny yet powerful database engine. Besides Android, it can be found in: Apple iphone
More informationAutomatically persisted among application sessions
STORAGE OPTIONS Storage options SharedPreference Small amount of data, as Key-value pairs Private to an Activity or Shared among Activities Internal storage Small to medium amount of data Private to the
More informationCS378 -Mobile Computing. Persistence
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 to reclaim resources but may be recreated later 2 Storing
More informationSqlite Update Failed With Error Code 19 Android
Sqlite Update Failed With Error Code 19 Android i'm wrote simple DataBaseHelper to use SQlite in android. after create class as : static final int DATABASE_VERSION = 1, private SQLiteDatabase mdatabase,
More informationMOBILE APPLICATIONS PROGRAMMING
Data Storage 23.12.2015 MOBILE APPLICATIONS PROGRAMMING Krzysztof Pawłowski Polsko-Japońska Akademia Technik Komputerowych STORAGE OPTIONS Shared Preferences SQLite Database Internal Storage External Storage
More informationCS378 -Mobile Computing. Persistence -SQLite
CS378 -Mobile Computing Persistence -SQLite Databases RDBMS relational data base management system Relational databases introduced by E. F. Codd Turing Award Winner Relational Database data stored in tables
More informationAndroid Programming Lecture 16 11/4/2011
Android Programming Lecture 16 11/4/2011 New Assignment Discuss New Assignment for CityApp GetGPS Search Web Service Parse List Coordinates Questions from last class It does not appear that SQLite, in
More informationLearn about Android Content Providers and SQLite
Tampa Bay Android Developers Group Learn about Android Content Providers and SQLite Scott A. Thisse March 20, 2012 Learn about Android Content Providers and SQLite What are they? How are they defined?
More informationSharedPreference. <map> <int name="access_count" value="3" /> </map>
1 Android Data Storage Options Android provides several data storage options for you to save persistent application data depends on your specific needs: private/public, small/large datasets :- Internal
More informationCS371m - Mobile Computing. Content Providers And Content Resolvers
CS371m - Mobile Computing Content Providers And Content Resolvers Content Providers One of the four primary application components: activities content providers / content resolvers services broadcast receivers
More informationAndroid Components Android Smartphone Programming. Outline University of Freiburg. Data Storage Database University of Freiburg. Notizen.
Android Components Android Smartphone Programming Matthias Keil Institute for Computer Science Faculty of Engineering 4. November 2013 Outline 1 2 Messages to the User 3 Background Work 4 App Widgets 5
More informationAndroid Components. Android Smartphone Programming. Matthias Keil. University of Freiburg
Android Components Android Smartphone Programming Matthias Keil Institute for Computer Science Faculty of Engineering 3. November 2014 Outline 1 Data Storage 2 Messages to the User 3 Background Work 4
More informationUniversity of Texas at Arlington, TX, USA
Dept. of Computer Science and Engineering University of Texas at Arlington, TX, USA A file is a collec%on of data that is stored on secondary storage like a disk or a thumb drive. Accessing a file means
More informationPermissions. Lecture 18
Permissions Lecture 18 Topics related Android permissions Defining & using applica:on permissions Component permissions Permissions Android protects resources & data with permissions Example: who has the
More informationObject-Oriented Databases Object-Relational Mappings and Frameworks. Alexandre de Spindler Department of Computer Science
Object-Oriented Databases Object-Relational Mappings and Frameworks Challenges Development of software that runs on smart phones. Data needs to outlive program execution Use of sensors Integration with
More informationSoftware Engineering Large Practical: Preferences, storage, and testing
Software Engineering Large Practical: Preferences, storage, and testing Stephen Gilmore (Stephen.Gilmore@ed.ac.uk) School of Informatics November 9, 2016 Contents A simple counter activity Preferences
More informationProduced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology
Mobile Application Development Produced by David Drohan (ddrohan@wit.ie) Department of Computing & Mathematics Waterford Institute of Technology http://www.wit.ie Android Persistence," Multithreading &
More informationLibraries are wri4en in C/C++ and compiled for the par>cular hardware.
marakana.com 1 marakana.com 2 marakana.com 3 marakana.com 4 Libraries are wri4en in C/C++ and compiled for the par>cular hardware. marakana.com 5 The Dalvik virtual machine is a major piece of Google's
More informationIn-app Billing Version 3
13 In-app Billing Version 3 Bruno Oliveira Developer Relations, Android 13 In-app billing! 2 In-app billing! Implement ALL the billing! 2 In-app billing! DO NOT WANT 2 PREVIOUSLY IN IN-APP BILLING 3 Easy
More informationAndroid Application Model II. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.
Android Application Model II CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr. Rajiv Ramnath 1 Outline Activity Lifecycle Services Persistence Content
More informationArray Basics: Outline
Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and
More informationLecture 2 Android SDK
Lecture 2 Android SDK This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a
More informationMyDatabaseHelper. public static final String TABLE_NAME = "tbl_bio";
Page 1 of 5 MyDatabaseHelper import android.content.context; import android.database.sqlite.sqliteopenhelper; class MyDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "friend_db";
More informationAndroid User Interface Overview. Most of the material in this sec7on comes from h8p://developer.android.com/guide/topics/ui/index.
Android User Interface Overview Most of the material in this sec7on comes from h8p://developer.android.com/guide/topics/ui/index.html Android User Interface User interface built using views and viewgroup
More informationM.C.A. Semester V Subject: - Mobile Computing (650003) Week : 1
M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 1 1) Explain underlying architecture of Android Platform. (Unit :- 1, Chapter :- 1) Suggested Answer:- Draw Figure: 1.8 from textbook given
More informationLoca%on Support in Android. COMP 355 (Muppala) Location Services and Maps 1
Loca%on Support in Android COMP 355 (Muppala) Location Services and Maps 1 Loca%on Services in Android Loca%on capabili%es for applica%ons supported through the classes in android.loca%on package and Google
More informationEncapsula)on, cont d. Polymorphism, Inheritance part 1. COMP 401, Spring 2015 Lecture 7 1/29/2015
Encapsula)on, cont d. Polymorphism, Inheritance part 1 COMP 401, Spring 2015 Lecture 7 1/29/2015 Encapsula)on In Prac)ce Part 2: Separate Exposed Behavior Define an interface for all exposed behavior In
More information10/7/15. MediaItem tostring Method. Objec,ves. Using booleans in if statements. Review. Javadoc Guidelines
Objec,ves Excep,ons Ø Wrap up Files Streams MediaItem tostring Method public String tostring() { String classname = getclass().tostring(); StringBuilder rep = new StringBuilder(classname); return rep.tostring();
More informationContentProvider & ContentResolver ContentResolver methods CursorLoader Implementing ContentProviders
ContentProvider & ContentResolver ContentResolver methods CursorLoader Implementing ContentProviders Represents a repository of structured data Encapsulates data sets Enforces data access permissions Intended
More informationWriting Efficient Drive Apps for Android. Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations
Writing Efficient Drive Apps for Android Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations Raise your hand if you use Google Drive source: "put your hands up!" (CC-BY) Raise the other
More informationAndroid File & Storage
Files Lecture 9 Android File & Storage Android can read/write files from two locations: Internal (built into the device) and external (an SD card or other drive attached to device) storage Both are persistent
More informationClasses and objects. Chapter 2: Head First Java: 2 nd Edi4on, K. Sierra, B. Bates
Classes and objects Chapter 2: Head First Java: 2 nd Edi4on, K. Sierra, B. Bates Fundamentals of Computer Science Keith Vertanen Copyright 2013 A founda4on for programming any program you might want to
More informationJonathan Aldrich Charlie Garrod
Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 3: Design Case Studies Design Case Study: Java I/O Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework
More informationAndroid Programming Lecture 15 11/2/2011
Android Programming Lecture 15 11/2/2011 City Web Service Documentation: http://206.219.96.5/webcatalog/ Need a web services client library: KSOAP2 Acts as our function calling proxy Allows us to generate
More informationDocument Databases: MongoDB
NDBI040: Big Data Management and NoSQL Databases hp://www.ksi.mff.cuni.cz/~svoboda/courses/171-ndbi040/ Lecture 9 Document Databases: MongoDB Marn Svoboda svoboda@ksi.mff.cuni.cz 28. 11. 2017 Charles University
More informationBackground. IBM sold expensive mainframes to large organiza<ons. Monitor sits between one or more OSes and HW
Virtual Machines Background IBM sold expensive mainframes to large organiza
More informationAndroid Application Development 101. Jason Chen Google I/O 2008
Android Application Development 101 Jason Chen Google I/O 2008 Goal Get you an idea of how to start developing Android applications Introduce major Android application concepts Provide pointers for where
More informationCS 193A. Activity state and preferences
CS 193A Activity state and preferences This document is copyright (C) Marty Stepp and Stanford Computer Science. Licensed under Creative Commons Attribution 2.5 License. All rights reserved. Activity instance
More informationBackground. IBM sold expensive mainframes to large organiza<ons. Monitor sits between one or more OSes and HW
Virtual Machines Background IBM sold expensive mainframes to large organiza
More informationSerialisa(on, Callbacks, Remote Object Ac(va(on. CS3524 Distributed Systems Lecture 03
Serialisa(on, Callbacks, Remote Object Ac(va(on CS3524 Distributed Systems Lecture 03 Serializa(on Client Object Serialize De-Serialize Byte Stream Byte Stream Server Object De-Serialize Serialize How
More informationLecture 17 Java Remote Method Invoca/on
CMSC 433 Fall 2014 Sec/on 0101 Mike Hicks (slides due to Rance Cleaveland) Lecture 17 Java Remote Method Invoca/on 11/4/2014 2012-14 University of Maryland 0 Recall Concurrency Several opera/ons may be
More informationJava. Package, Interface & Excep2on
Java Package, Interface & Excep2on Package 2 Package Java package provides a mechanism for par55oning the class name space into more manageable chunks Both naming and visibility control mechanism Define
More informationMr. Pritesh N. Patel Assistant Professor MCA ISTAR, V. V. Nagar ANDROID DATABASE TUTORIAL
Mr. Pritesh N. Patel Assistant Professor MCA ISTAR, V. V. Nagar ANDROID DATABASE TUTORIAL Mr. Pritesh N. Patel 1 Storage Options Android provides several options for you to save persistent application
More informationAtmiya Institute of Technology & Science, Rajkot Department of MCA
Atmiya Institute of Technology & Science, Rajkot Department of MCA Chapter 10 Application Preference (/data/data//shared_prefs/.xml) Private Preference (Data sharing
More informationXML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.
XML Tutorial XML stands for extensible Markup Language. XML is a markup language much like HTML used to describe data. XML tags are not predefined in XML. We should define our own Tags. Xml is well readable
More informationCS Android. Vitaly Shmatikov
CS 5450 Android Vitaly Shmatikov Structure of Android Applications Applications include multiple components Activities: user interface Services: background processing Content providers: data storage Broadcast
More informationAndroid Camera. Alexander Nelson October 6, University of Arkansas - Department of Computer Science and Computer Engineering
Android Camera Alexander Nelson October 6, 2017 University of Arkansas - Department of Computer Science and Computer Engineering Why use the camera? Why not? Translate Call Learn Capture How to use the
More informationHistory of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995
Java Introduc)on History of Java Java was originally developed by Sun Microsystems star:ng in 1991 James Gosling Patrick Naughton Chris Warth Ed Frank Mike Sheridan This language was ini:ally called Oak
More informationProgramming Environments
Programming Environments There are several ways of crea/ng a computer program Using an Integrated Development Environment (IDE) Using a text editor You should use the method you are most comfortable with.
More informationADF Mobile Code Corner
ADF Mobile Code Corner m05. Caching WS queried data local for create, read, update with refresh from DB and offline capabilities Abstract: The current version of ADF Mobile supports three ADF data controls:
More informationDebojyoti Jana (Roll ) Rajrupa Ghosh (Roll ) Sreya Sengupta (Roll )
DINABANDHU ANDREWS INSTITUTE OF TECHNOLOGY AND MANAGEMENT (Affiliated to West Bengal University of Technology also known as Maulana Abul Kalam Azad University Of Technology) Project report on ANDROID QUIZ
More informationGeneric programming POLYMORPHISM 10/25/13
POLYMORPHISM Generic programming! Code reuse: an algorithm can be applicable to many objects! Goal is to avoid rewri:ng as much as possible! Example: int sqr(int i, int j) { return i*j; double sqr(double
More informationFile Operations in Java. File handling in java enables to read data from and write data to files
Description Java Basics File Operations in Java File handling in java enables to read data from and write data to files along with other file manipulation tasks. File operations are present in java.io
More informationEMBEDDED SYSTEMS PROGRAMMING SQLite
EMBEDDED SYSTEMS PROGRAMMING 2017-18 SQLite DATA STORAGE: ANDROID Shared Preferences Filesystem: internal storage Filesystem: external storage SQLite (Also available in ios and WP) Network (e.g., Google
More informationReview. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases
Objec,ves PostgreSQL DB Elas,csearch Review Databases Ø What language do we use to query databases? March 8, 2017 Sprenkle - CSCI397 1 March 8, 2017 Sprenkle - CSCI397 2 Database Overview Store data in
More informationCSE Opera,ng System Principles
CSE 30341 Opera,ng System Principles Lecture 5 Processes / Threads Recap Processes What is a process? What is in a process control bloc? Contrast stac, heap, data, text. What are process states? Which
More informationCS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle
CS378 -Mobile Computing Anatomy of and Android App and the App Lifecycle Hello Android Tutorial http://developer.android.com/resources/tutorials/hello-world.html Important Files src/helloandroid.java Activity
More informationAndroid Tasks and Back Stack
Android Tasks and Back Stack Applica2ons, Ac2vi2es and Tasks Task Main ac2vity Mail composer contacts menu welcome Mail Course Info Back stack Applica2on/Process COMP 4521 (Muppala) Android Tasks and Back
More informationApplication Fundamentals
Application Fundamentals CS 2046 Mobile Application Development Fall 2010 Announcements CMS is up If you did not get an email regarding this, see me after class or send me an email. Still working on room
More informationThe Internet. CS 2046 Mobile Application Development Fall Jeff Davidson CS 2046
The Internet CS 2046 Mobile Application Development Fall 2010 Announcements HW2 due Monday, 11/8, at 11:59pm If you want to know what it means to root your phone, or what this does, see Newsgroup HW1 grades
More informationMobile Development Lecture 11: Activity State and Preferences
Mobile Development Lecture 11: Activity State and Preferences Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Elgayyar.weebly.com Activity Instance State Instance state: Current state of an activity. Which boxes
More informationDesktop Integrators You Mean I Can Load Data Straight From a Spreadsheet? Lee Briggs Director, Financials Denovo
Desktop Integrators You Mean I Can Load Data Straight From a Spreadsheet? Lee Briggs Director, Financials Prac@ce Denovo LBriggs@Denovo-us.com Agenda Introduc@ons Applica@on Desktop Integrator and Web-ADI
More informationManaged So*ware Installa1on with Munki
Managed So*ware Installa1on with Munki Jon Rhoades St Vincent s Ins1tute & University of Melbourne jrhoades@svi.edu.au Managed Installa1on Why? What are we using now? Needs Installs Updates Apple Updates
More informationManaging Data. However, we'll be looking at two other forms of persistence today: (shared) preferences, and databases.
Managing Data This week, we'll be looking at managing information. There are actually many ways to store information for later retrieval. In fact, feel free to take a look at the Android Developer pages:
More informationSoftware Engineering Large Practical: Storage, Settings and Layouts. Stephen Gilmore School of Informatics October 27, 2017
Software Engineering Large Practical: Storage, Settings and Layouts Stephen Gilmore School of Informatics October 27, 2017 Contents 1. Storing information 2. Settings 3. Layouts 1 Storing information Storage
More informationCOSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan
COSC 111: Computer Programming I Dr. Bowen Hui University of Bri>sh Columbia Okanagan 1 First half of course SoEware examples From English to Java Template for building small programs Exposure to Java
More informationCOSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan
COSC 111: Computer Programming I Dr. Bowen Hui University of Bri>sh Columbia Okanagan 1 Administra>on Midterm 2 To return next class Assignment 3 Available on website Due next Thursday Today Sta>c modifier
More informationCS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++
CS101: Fundamentals of Computer Programming Dr. Tejada stejada@usc.edu www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ 10 Stacks of Coins You have 10 stacks with 10 coins each that look and feel
More informationEncapsula)on CMSC 202
Encapsula)on CMSC 202 Types of Programmers Class creators Those developing new classes Want to build classes that expose the minimum interface necessary for the client program and hide everything else
More informationCon$nuous Integra$on Development Environment. Kovács Gábor
Con$nuous Integra$on Development Environment Kovács Gábor kovacsg@tmit.bme.hu Before we start anything Select a language Set up conven$ons Select development tools Set up development environment Set up
More informationMobile Application Programing: Android. Data Persistence
Mobile Application Programing: Android Data Persistence Activities Apps are composed of activities Activities are self-contained tasks made up of one screen-full of information Activities start one another
More informationGarbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }
Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;
More informationWays to implement a language
Interpreters Implemen+ng PLs Most of the course is learning fundamental concepts for using PLs Syntax vs. seman+cs vs. idioms Powerful constructs like closures, first- class objects, iterators (streams),
More information