This document discusses persistent data storage options in Android, focusing on SQLite database usage. It describes how SQLite provides a small, relational database system for Android apps. The key classes for interacting with SQLite in Android are SQLiteDatabase, ContentValues, and SQLiteOpenHelper. SQLiteOpenHelper provides helper methods for opening a database and handling schema changes. The document provides examples for inserting, updating, deleting, and querying data in an SQLite database using these classes.
This document provides an overview of different data storage options in Android including shared preferences, internal storage, external storage, SQLite databases, and network connections. It also includes examples and workshops for using each data storage type with key points on shared preferences, internal and external storage paths, SQLiteOpenHelper, CRUD operations, and displaying data in a ListView.
This document provides instructions for using an SQLite database in an Android application to store and manage student data. It describes creating model and helper classes to define the student data structure and perform CRUD operations on the database. These include a StudentInfo model class to store student attributes, a DBHelper class extending SQLiteOpenHelper to handle database creation and operations like insert, update, delete and fetch. Layout files are created for listing student records, and an adapter class connects the database records to list views. The tutorial then explains creating activities to display and manage the student data using these classes.
The document discusses how to use SQLite database in Android applications. It covers creating a SQLiteHelper class to manage the database, defining model classes, and performing CRUD operations like inserting, updating, deleting and selecting records. Layouts are created for displaying records and for data entry forms. The onCreate() and onUpgrade() methods of SQLiteHelper are used to create and manage the database and tables.
Android provides several options for storing application data, including Shared Preferences, internal storage, external storage, SQLite databases, and network connections. Shared Preferences allows storing private primitive data in key-value pairs and is best for saving user preferences. Internal storage stores private data on the device memory, while external storage stores public data on shared external storage like an SD card. SQLite databases allow storing structured data in a private database. The document then provides code examples for using Shared Preferences to save and retrieve a string to demonstrate how to save application data persistently on the device.
This document provides an overview of Android application development training on accessing and manipulating data using SQLite databases on Android. It covers topics like what SQLite is, creating and connecting to databases, setting database properties, creating tables, inserting, updating, and deleting records from the databases using ContentValues and SQLiteDatabase methods. Code examples are provided for each topic.
This document provides an overview and tutorial for using SQLite database tools in Android application development. It discusses the SQLiteOpenHelper and SQLiteDatabase classes, which are used to create, open, and manage an app's database. It then demonstrates how to create a database manager class that extends SQLiteOpenHelper to define the database structure, and includes methods like addRow(), deleteRow(), and updateRow() to interact with the database. The goal is to build reusable database functionality that can be included in most Android apps.
This document discusses using SQLite databases in Android applications. SQLite is an embedded SQL database that does not require a separate server. It is included in the Android SDK and can be used to create and query database files. The document explains how to open a database, create tables, insert/update/delete rows using SQL queries, and retrieve data using cursors. Raw queries and simple queries can be used to perform retrieval queries on a single table. Transactions are used to commit or roll back changes to the database.
This document discusses different methods for data storage in Android applications, including:
1. Accessing files from the raw resource folder or external storage for static files.
2. Using shared preferences to store key-value pairs for default values or UI state.
3. Accessing a local SQLite database with a helper DAO class to perform CRUD operations like inserting, selecting, updating, and deleting rows of data.
The exercises provide examples of updating a sample project to load and store contact data using these different storage methods.
This document provides an overview of different data storage options in Android including shared preferences, internal storage, external storage, SQLite databases, and network connections. It also includes examples and workshops for using each data storage type with key points on shared preferences, internal and external storage paths, SQLiteOpenHelper, CRUD operations, and displaying data in a ListView.
This document provides instructions for using an SQLite database in an Android application to store and manage student data. It describes creating model and helper classes to define the student data structure and perform CRUD operations on the database. These include a StudentInfo model class to store student attributes, a DBHelper class extending SQLiteOpenHelper to handle database creation and operations like insert, update, delete and fetch. Layout files are created for listing student records, and an adapter class connects the database records to list views. The tutorial then explains creating activities to display and manage the student data using these classes.
The document discusses how to use SQLite database in Android applications. It covers creating a SQLiteHelper class to manage the database, defining model classes, and performing CRUD operations like inserting, updating, deleting and selecting records. Layouts are created for displaying records and for data entry forms. The onCreate() and onUpgrade() methods of SQLiteHelper are used to create and manage the database and tables.
Android provides several options for storing application data, including Shared Preferences, internal storage, external storage, SQLite databases, and network connections. Shared Preferences allows storing private primitive data in key-value pairs and is best for saving user preferences. Internal storage stores private data on the device memory, while external storage stores public data on shared external storage like an SD card. SQLite databases allow storing structured data in a private database. The document then provides code examples for using Shared Preferences to save and retrieve a string to demonstrate how to save application data persistently on the device.
This document provides an overview of Android application development training on accessing and manipulating data using SQLite databases on Android. It covers topics like what SQLite is, creating and connecting to databases, setting database properties, creating tables, inserting, updating, and deleting records from the databases using ContentValues and SQLiteDatabase methods. Code examples are provided for each topic.
This document provides an overview and tutorial for using SQLite database tools in Android application development. It discusses the SQLiteOpenHelper and SQLiteDatabase classes, which are used to create, open, and manage an app's database. It then demonstrates how to create a database manager class that extends SQLiteOpenHelper to define the database structure, and includes methods like addRow(), deleteRow(), and updateRow() to interact with the database. The goal is to build reusable database functionality that can be included in most Android apps.
This document discusses using SQLite databases in Android applications. SQLite is an embedded SQL database that does not require a separate server. It is included in the Android SDK and can be used to create and query database files. The document explains how to open a database, create tables, insert/update/delete rows using SQL queries, and retrieve data using cursors. Raw queries and simple queries can be used to perform retrieval queries on a single table. Transactions are used to commit or roll back changes to the database.
This document discusses different methods for data storage in Android applications, including:
1. Accessing files from the raw resource folder or external storage for static files.
2. Using shared preferences to store key-value pairs for default values or UI state.
3. Accessing a local SQLite database with a helper DAO class to perform CRUD operations like inserting, selecting, updating, and deleting rows of data.
The exercises provide examples of updating a sample project to load and store contact data using these different storage methods.
SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration. You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform. In this chapter we will discuss about developing application with SQLite.
Storing data is a basic and very common need in mobile apps. The Android application framework provides several storage options, one of which is SQLite databases.
In this tutorial you will see a simple Android database example. The example is based on the Android ListView Tutorial and the Android AsyncTask Tutorial, however these tutorials are not mandatory for the purpose of understanding the principles of proper Android database usage.
The document discusses using SQLite database in Android applications. It explains that SQLite is a lightweight database that can be used to store and retrieve data in Android apps. It provides steps to create a database, add and retrieve records, and use the SQLiteOpenHelper class. Methods like onCreate(), onUpgrade(), and onOpen() are called at different stages of the database lifecycle. The document also discusses updating, deleting, and implementing the database in an example Android application.
The document discusses various options for data storage in Android applications, including shared preferences, internal storage, external storage, SQLite databases, and network connections. It provides details on when each option would be suitable and code examples for using shared preferences, internal storage, and SQLite databases to store persistent data in key-value pairs, files, and structured databases, respectively. The document also covers best practices for accessing external storage and creating databases using the SQLiteOpenHelper class or directly with SQLiteDatabase objects.
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. It is often used for local/client storage in applications. Key points:
- Created by D. Richard Hipp, it provides a lightweight disk-based database that doesn't require a separate server process and allows accessing the database using SQL queries.
- The entire database is stored in a single cross-platform file and can be as small as 0.5MB, making it suitable for embedded and mobile applications.
- It supports common data types like NULL, INTEGER, REAL, TEXT, and BLOB and is used in standalone apps, local
SQLite is a lightweight database that can be used to persist data between sessions of an Android app. The SQLiteOpenHelper class manages database creation and upgrading, and provides methods like onCreate() and onUpgrade() to define how the database schema is set up. Queries can be performed on the database using the query() method of the SQLiteDatabase class to retrieve data as a Cursor object.
The document discusses using SQLite as the database for Android applications, including its history, advantages for mobile use, features, architecture, and examples of creating SQLite databases and performing basic CRUD operations in Android code. It provides an overview of SQLite's lightweight and portable design that makes it suitable for embedded systems like mobile devices.
09.1. Android - Local Database (Sqlite)Oum Saokosal
This document provides information about SQLite databases in Android applications. It discusses how SQLite is integrated into the Android runtime, demonstrates basic SQL statements for creating tables, inserting, updating, deleting and selecting records, and shows code examples for executing SQL statements and retrieving data using a Cursor object in an Android app. It also explains how to view the database files on an Android emulator.
This document provides instructions for connecting an SQLite database to an Android application using Android Studio. It describes creating a database using SQLite Manager and placing it in the Android project's assets folder. It then explains creating a Connection class with paths to the database folder and file. The document outlines creating a DataDB class to connect to the Connection class and calling getNameDB in the MainActivity to retrieve the database name. It provides code snippets for the Connection and DataDB classes.
The document discusses various data storage options in Android including shared preferences, internal storage, external storage, SQLite databases, and network/cloud storage. It provides details on how to use shared preferences to store private data in key-value pairs, how to read and write files to internal and external storage, how to create and manage SQLite databases to store structured data, and lists some popular cloud storage providers.
1. Shared preferences are used to store private primitive data in key-value pairs and the data is stored in an XML file.
2. Internal storage is used to store private files on the device memory and external storage stores public data on the shared external storage like an SD card.
3. SQLite database stores structured data in a private database on the internal storage and it allows for complex queries of the data.
The document discusses various data storage options for Android applications, including shared preferences, internal and external file storage, and SQLite databases. It provides code examples for reading and writing data to shared preferences files and internal storage, as well as implementing a SQLite database using SQLiteOpenHelper and performing common CRUD operations.
The document discusses attacks on collaborative recommendation systems. It finds that relatively small attacks can be effective at influencing recommendations. Various attack types are explored, including average, bandwagon, segment and nuke attacks. Detection methods are also examined, such as clustering, dimensionality reduction and supervised classification. While detection makes attacks less effective, obfuscated attacks remain a challenge. Overall, the document analyzes how to model and defend against attacks aimed at manipulating the insights provided by collaborative systems.
This document provides an overview of Visual Studio 2012, Microsoft's integrated development environment. Some key points:
- Visual Studio 2012 allows developers to create applications for multiple platforms like Windows, Windows Phone, and Xbox. It also supports development for the web and cloud.
- The interface is streamlined for focus on development tasks. Productivity is enhanced through faster build times and improved debugging tools.
- Visual Studio supports an evolving software development model where other stakeholders are involved earlier. It facilitates capturing changing requirements.
- New platforms and app stores present challenges and opportunities for reaching new markets. Visual Studio aids in multi-platform development and publishing applications to stores.
This document discusses SOAP (Simple Object Access Protocol), the standard messaging protocol used by web services. It describes SOAP as a lightweight protocol that allows applications to exchange messages and data between disparate systems. The key topics covered include SOAP's use as an inter-application communication protocol, the structure of SOAP messages containing an envelope with optional header and mandatory body elements, and how SOAP messages are transported over HTTP. The document also discusses SOAP headers, bodies, faults, and intermediaries in the SOAP communication model.
This document is a tutorial on how to set up an Android development environment to build Android Wear apps. It discusses downloading and installing the Java Development Kit (JDK), Android Studio IDE, Android SDK, and creating an Android Virtual Device (AVD) emulator. It then demonstrates creating a new Android Wear project from a sample app provided by Google and running the app on the AVD emulator. The tutorial is intended for beginners and covers the basic setup and running of a simple Android Wear app.
Team Foundation Server (TFS) is at the center of Visual Studio 2010 and provides work item tracking, version control, test case management, build management, and reporting capabilities. TFS allows linking different work items together to provide traceability across requirements, tasks, test cases, and bugs. It also manages changes to source code and other project artifacts through version control and facilitates automated builds.
This document provides an overview of beginning Android development. It discusses advantages like low barrier to entry and familiar Java programming, as well as disadvantages like device fragmentation. It also covers Android-specific topics like Android Studio IDE, activities, intents, manifest files, and components. The document demonstrates example code for intents and provides resources for learning more about Android development.
The document provides instructions for setting up the AWS Toolkit for Visual Studio, including:
1. Installing the toolkit by running the installation wizard which is packaged as an MSI file.
2. Specifying AWS credentials by adding profiles to the SDK Store which stores the encrypted credentials. Profiles require an access key, secret key, and account type.
3. The SDK Store is separate from project directories and supports multiple credential profiles from different accounts. At least one profile must be added to use the toolkit.
Secc tutorials development and deployment of rest web services in java_v2.0Aravindharamanan S
This document provides a tutorial on developing and deploying REST web services in Java. It introduces REST as an architectural style for web services that uses simple HTTP requests and focuses on representing resources with URIs. The tutorial demonstrates building a basic "Hello World" REST service in Java and developing an Android client to access these RESTful services. It explains the key REST principles of using HTTP methods to perform CRUD operations on resources and representing everything as URIs in a stateless manner.
This release notes document provides an overview of the JAX-WS RI 2.2.6 release, including new features such as support for JAX-WS 2.2, development tools like wsimport and wsgen, standards compliance for WS-Addressing and SOAP 1.1/1.2, and extensions for security, transactions and interoperability. It also lists bugs fixed, known issues, installation instructions, and links to additional documentation.
SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration. You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform. In this chapter we will discuss about developing application with SQLite.
Storing data is a basic and very common need in mobile apps. The Android application framework provides several storage options, one of which is SQLite databases.
In this tutorial you will see a simple Android database example. The example is based on the Android ListView Tutorial and the Android AsyncTask Tutorial, however these tutorials are not mandatory for the purpose of understanding the principles of proper Android database usage.
The document discusses using SQLite database in Android applications. It explains that SQLite is a lightweight database that can be used to store and retrieve data in Android apps. It provides steps to create a database, add and retrieve records, and use the SQLiteOpenHelper class. Methods like onCreate(), onUpgrade(), and onOpen() are called at different stages of the database lifecycle. The document also discusses updating, deleting, and implementing the database in an example Android application.
The document discusses various options for data storage in Android applications, including shared preferences, internal storage, external storage, SQLite databases, and network connections. It provides details on when each option would be suitable and code examples for using shared preferences, internal storage, and SQLite databases to store persistent data in key-value pairs, files, and structured databases, respectively. The document also covers best practices for accessing external storage and creating databases using the SQLiteOpenHelper class or directly with SQLiteDatabase objects.
SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. It is often used for local/client storage in applications. Key points:
- Created by D. Richard Hipp, it provides a lightweight disk-based database that doesn't require a separate server process and allows accessing the database using SQL queries.
- The entire database is stored in a single cross-platform file and can be as small as 0.5MB, making it suitable for embedded and mobile applications.
- It supports common data types like NULL, INTEGER, REAL, TEXT, and BLOB and is used in standalone apps, local
SQLite is a lightweight database that can be used to persist data between sessions of an Android app. The SQLiteOpenHelper class manages database creation and upgrading, and provides methods like onCreate() and onUpgrade() to define how the database schema is set up. Queries can be performed on the database using the query() method of the SQLiteDatabase class to retrieve data as a Cursor object.
The document discusses using SQLite as the database for Android applications, including its history, advantages for mobile use, features, architecture, and examples of creating SQLite databases and performing basic CRUD operations in Android code. It provides an overview of SQLite's lightweight and portable design that makes it suitable for embedded systems like mobile devices.
09.1. Android - Local Database (Sqlite)Oum Saokosal
This document provides information about SQLite databases in Android applications. It discusses how SQLite is integrated into the Android runtime, demonstrates basic SQL statements for creating tables, inserting, updating, deleting and selecting records, and shows code examples for executing SQL statements and retrieving data using a Cursor object in an Android app. It also explains how to view the database files on an Android emulator.
This document provides instructions for connecting an SQLite database to an Android application using Android Studio. It describes creating a database using SQLite Manager and placing it in the Android project's assets folder. It then explains creating a Connection class with paths to the database folder and file. The document outlines creating a DataDB class to connect to the Connection class and calling getNameDB in the MainActivity to retrieve the database name. It provides code snippets for the Connection and DataDB classes.
The document discusses various data storage options in Android including shared preferences, internal storage, external storage, SQLite databases, and network/cloud storage. It provides details on how to use shared preferences to store private data in key-value pairs, how to read and write files to internal and external storage, how to create and manage SQLite databases to store structured data, and lists some popular cloud storage providers.
1. Shared preferences are used to store private primitive data in key-value pairs and the data is stored in an XML file.
2. Internal storage is used to store private files on the device memory and external storage stores public data on the shared external storage like an SD card.
3. SQLite database stores structured data in a private database on the internal storage and it allows for complex queries of the data.
The document discusses various data storage options for Android applications, including shared preferences, internal and external file storage, and SQLite databases. It provides code examples for reading and writing data to shared preferences files and internal storage, as well as implementing a SQLite database using SQLiteOpenHelper and performing common CRUD operations.
The document discusses attacks on collaborative recommendation systems. It finds that relatively small attacks can be effective at influencing recommendations. Various attack types are explored, including average, bandwagon, segment and nuke attacks. Detection methods are also examined, such as clustering, dimensionality reduction and supervised classification. While detection makes attacks less effective, obfuscated attacks remain a challenge. Overall, the document analyzes how to model and defend against attacks aimed at manipulating the insights provided by collaborative systems.
This document provides an overview of Visual Studio 2012, Microsoft's integrated development environment. Some key points:
- Visual Studio 2012 allows developers to create applications for multiple platforms like Windows, Windows Phone, and Xbox. It also supports development for the web and cloud.
- The interface is streamlined for focus on development tasks. Productivity is enhanced through faster build times and improved debugging tools.
- Visual Studio supports an evolving software development model where other stakeholders are involved earlier. It facilitates capturing changing requirements.
- New platforms and app stores present challenges and opportunities for reaching new markets. Visual Studio aids in multi-platform development and publishing applications to stores.
This document discusses SOAP (Simple Object Access Protocol), the standard messaging protocol used by web services. It describes SOAP as a lightweight protocol that allows applications to exchange messages and data between disparate systems. The key topics covered include SOAP's use as an inter-application communication protocol, the structure of SOAP messages containing an envelope with optional header and mandatory body elements, and how SOAP messages are transported over HTTP. The document also discusses SOAP headers, bodies, faults, and intermediaries in the SOAP communication model.
This document is a tutorial on how to set up an Android development environment to build Android Wear apps. It discusses downloading and installing the Java Development Kit (JDK), Android Studio IDE, Android SDK, and creating an Android Virtual Device (AVD) emulator. It then demonstrates creating a new Android Wear project from a sample app provided by Google and running the app on the AVD emulator. The tutorial is intended for beginners and covers the basic setup and running of a simple Android Wear app.
Team Foundation Server (TFS) is at the center of Visual Studio 2010 and provides work item tracking, version control, test case management, build management, and reporting capabilities. TFS allows linking different work items together to provide traceability across requirements, tasks, test cases, and bugs. It also manages changes to source code and other project artifacts through version control and facilitates automated builds.
This document provides an overview of beginning Android development. It discusses advantages like low barrier to entry and familiar Java programming, as well as disadvantages like device fragmentation. It also covers Android-specific topics like Android Studio IDE, activities, intents, manifest files, and components. The document demonstrates example code for intents and provides resources for learning more about Android development.
The document provides instructions for setting up the AWS Toolkit for Visual Studio, including:
1. Installing the toolkit by running the installation wizard which is packaged as an MSI file.
2. Specifying AWS credentials by adding profiles to the SDK Store which stores the encrypted credentials. Profiles require an access key, secret key, and account type.
3. The SDK Store is separate from project directories and supports multiple credential profiles from different accounts. At least one profile must be added to use the toolkit.
Secc tutorials development and deployment of rest web services in java_v2.0Aravindharamanan S
This document provides a tutorial on developing and deploying REST web services in Java. It introduces REST as an architectural style for web services that uses simple HTTP requests and focuses on representing resources with URIs. The tutorial demonstrates building a basic "Hello World" REST service in Java and developing an Android client to access these RESTful services. It explains the key REST principles of using HTTP methods to perform CRUD operations on resources and representing everything as URIs in a stateless manner.
This release notes document provides an overview of the JAX-WS RI 2.2.6 release, including new features such as support for JAX-WS 2.2, development tools like wsimport and wsgen, standards compliance for WS-Addressing and SOAP 1.1/1.2, and extensions for security, transactions and interoperability. It also lists bugs fixed, known issues, installation instructions, and links to additional documentation.
This document provides a tutorial on collaborative filtering. It begins by defining collaborative filtering and providing everyday examples. It then outlines key aspects of collaborative filtering systems including memory-based recommendation algorithms, visualizing user similarities through item distances, and how collaborative filtering compares to content-based filtering. The document discusses algorithms for collaborative filtering and how collaborative filtering can be applied with different types of input data like true ratings or assumed ratings. It concludes by summarizing collaborative filtering and some of its applications.
Recommender systems allow online retailers to customize their sites to meet consumer tastes by aiding browsing and suggesting related items. Personalization is one of e-commerce's advantages over brick-and-mortar stores. Common techniques include item-to-item recommendations based on user ratings, user-to-user comparisons based on item preferences, and population-based suggestions of popular items. Challenges include obtaining user data, making novel recommendations, and addressing ethical issues.
1. The document provides instructions for installing and using Android Studio and IntelliJ IDEA to open and run example projects from the author's books on Android and Java development.
2. It includes steps for downloading Android Studio and IntelliJ IDEA, importing example projects, and running apps on emulators or real Android devices.
3. The document also provides a brief overview of the steps needed to create a new Android app project in Android Studio.
Collaborative filtering uses historical user preferences to predict how users will rate items they have not yet seen. It works by finding similarities between users or items and generating recommendations based on those similarities. Common collaborative filtering algorithms include user-based nearest neighbor, item-based nearest neighbor, and probabilistic models like Bayesian networks. Practical challenges include cold starts for new users/items, collecting accurate ratings data, and evaluating system performance. Privacy, trust, interface design and hybrid approaches combining collaborative and content-based filtering are also important issues.
This document discusses recommender systems and collaborative filtering. It defines recommender systems as tools that help users make decisions by recommending items based on their preferences or the preferences of similar users. It describes two main types of recommender systems: content-based systems, which recommend items similar to those a user liked in the past, and collaborative filtering systems, which recommend items liked by other users with similar tastes. The document uses the example of Amazon and MovieLens to illustrate how collaborative filtering works by finding relationships between users or items in a user-item rating matrix.
This document provides an overview and tutorial on Windows Communication Foundation (WCF). WCF is a framework for building and deploying distributed services over networks. It allows services to be hosted in any operating system process and enables communication via various bindings like basic HTTP and TCP. The tutorial explains WCF fundamentals like architecture, creating and hosting services, consuming services, different bindings and instance management. It also covers advanced topics such as transactions, WCF RIA services and security.
Item-based collaborative filtering recommends items to users based on the similarity between items, not users. It calculates item similarities based on how users have rated common items. To predict a user's rating for a new item, it takes a weighted average of the user's ratings for similar items, where the weights are the item similarities. This approach reduces the cold-start problem for new users and improves scalability compared to user-based collaborative filtering.
This document discusses SOAP web services. It begins with an introduction to web services, XML, and SOAP. SOAP is an XML-based protocol that allows for machine-readable documents to be passed over multiple connection protocols to create a distributed system. The document then discusses alternative distributed systems like CORBA, Java RMI, and XML-RPC. It analyzes the advantages and disadvantages of the SOAP protocol. It also covers service description using WSDL, service discovery including UDDI, and describes an MSc project that implements a SOAP web service for a BibTeX database.
Twdatasci cjlin-big data analytics - challenges and opportunitiesAravindharamanan S
The document discusses the challenges and opportunities of big data analytics. It outlines some key differences between traditional data mining and big data, such as the size of datasets exceeding the capacity of single computers. This requires distributed data mining or machine learning across multiple machines. However, distributing computations introduces technical challenges around communication, synchronization, and developing algorithms that can handle iterative access to large datasets. While opportunities exist to parallelize existing algorithms or design new distributed algorithms, it will take time to develop integrated tools that make big data analytics as easy as traditional data mining. Lessons can be drawn from how linear algebra routines were optimized to handle memory hierarchies efficiently. Success will depend on understanding both algorithms and distributed systems.
Create an android app for database creation using.pptxvishal choudhary
1) This document describes how to create an Android app to perform CRUD (create, read, update, delete) operations on a SQLite database.
2) It involves creating a SQLiteOpenHelper subclass to manage the database, along with methods to insert, query, update and delete data from the database table.
3) The Android app includes layout elements like buttons and text fields, and Java code to handle button clicks and call the appropriate database methods. Validation is also added to ensure required fields are populated.
This document discusses AndroQLite, a tool that can generate Java class files (models, helpers, controllers, constants) needed for SQLite database usage in Android projects. The tool allows developers to quickly create necessary files for basic data access methods like insert, delete, update, and get all records. Using AndroQLite involves downloading it from a website, adding table and field names, and clicking create to generate the Java files to then use in an Android project.
Android Training (Storing data using SQLite)Khaled Anaqwa
SQLite is an open-source database that is embedded into every Android device. It requires limited memory and supports standard SQL features. The document discusses how to use SQLite in Android applications by creating a SQLiteOpenHelper subclass to define database creation and updating methods. It also describes implementing a DAO interface to perform CRUD operations on the database and models.
Shared preferences allow storing private primitive data in key-value pairs that persists locally even when the app is closed. The data is accessible throughout the app. To use shared preferences, call getSharedPreferences() to get an instance, then use edit() to putString/commit values.
SQLite is Android's built-in SQL database that stores data to a text file. The SQLiteOpenHelper class manages database creation and updating. Tables can be created and rows inserted, read from, and updated. Room, ORMLite, and GreenDAO are popular ORM libraries that provide an abstraction layer over SQLite.
Permissions for dangerous resources like location must be requested at runtime in Android 6.0+. Check if the permission is granted
This document provides an overview of SQLite, including:
- SQLite is an embedded SQL database that is not a client-server system and stores the entire database in a single disk file.
- It supports ACID transactions for reliability and data integrity.
- SQLite is used widely in applications like web browsers, Adobe software, Android, and more due to its small size and not requiring a separate database server.
- The Android SDK includes classes for managing SQLite databases like SQLiteDatabase for executing queries, updates and deletes.
This is my small sample to know how to save data in SQLite database on android Apps.
I write this with direct sample code. i hope it can understandable
This document provides an overview of SQLite database usage in Android applications. It discusses that SQLite is an open source database that is included by default in Android Studio. It describes how to create a database class that extends SQLiteOpenHelper to connect to the database and perform CRUD operations. It also provides examples of how to create a table, insert data using ContentValues, and check stored data using an SQL browser tool.
SQLLite and Java
SQLite is an embedded SQL database that is not a client/server system but is instead accessed via function calls from an application. It uses a single cross-platform database file. The android.database.sqlite package provides classes for managing SQLite databases in Android applications, including methods for creating, opening, inserting, updating, deleting, and querying the database. Queries return results as a Cursor object that can be used to access data.
Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. It handles concerns like caching relevant data to access when offline and syncing changes to a server. There are three major Room components: the Database class that holds the database connection, Entities that represent tables, and DAOs that contain methods for database access. Room simplifies tasks like defining schemas, inserting/updating/deleting data, and handling schema changes through migrations.
This class defines a database helper that manages the underlying data repository for an Android content provider. It extends the SQLiteOpenHelper class and overrides required methods to create a database table called "students" with fields for id, name, and grade when the database is created, and to drop and recreate this table if the database version changes.
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...TAISEEREISA
SQLite is an embedded SQL database that is included within Android applications. It allows creating, querying, and modifying a database without a separate server process. Developers can open and query a SQLite database using methods like openDatabase(), rawQuery(), execSQL(), and insert()/update()/delete(). This allows storing and retrieving application data, even when the device is offline.
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenSony Suci
Model View Controller (MVC) adalah metode pemrograman C# yang dikembangkan oleh Microsoft untuk menjawab seluruh programmer dunia tentang pengembangan bahasa program secara mudah dalam penggunaannya seperti bahasa java yang menjadi populer belakangan ini.
SQLite is an open source SQL database that is embedded into mobile devices like Android. It uses little memory (250KB) and supports transactions and prepared statements. SQLite comes preinstalled on Android and application databases are stored in the data folder under the app name. The android.database and android.database.sqlite packages provide classes like SQLiteOpenHelper, SQLiteDatabase, and Cursor to perform operations like insert, update, delete, query, and rawQuery on the SQLite database.
StORM: a lightweight ORM for Android SQLiteDavid Chandler
Project stORM is an ORM library for SQLite on Android that aims to provide an easy and convention-based way to map objects to database tables. It uses annotation processing to generate database helper classes and data access objects (DAOs) that allow storing and querying objects with minimal boilerplate code or performance overhead. The library supports basic CRUD operations on objects as well as filtering and sorting but does not currently support object relationships or complex queries.
Zybotech solutions, offers job oriented courses on mobile application development for freshers and professionals with placement assistance, interactive training sessions with live project exposure.
This document discusses database security and SQL injection attacks. It begins with an overview of access control in SQL and views before discussing SQL injection attacks in more detail. The key points are that SQL injection attacks involve inserting malicious SQL statements into user input fields to exploit applications that directly insert user input into SQL queries. Examples are given of how attacks can read or delete entire databases. The best defenses include using prepared statements with bound parameters and validating/sanitizing all user input.
Here are 4 ways to mitigate code injection attacks:
1. Use parameterized queries or stored procedures instead of concatenating strings. This prevents user input from being interpreted as code.
2. Validate all user input and sanitize special characters. Remove characters like ';', '--', etc that could alter the meaning of the SQL query.
3. Limit account privileges to only what is necessary. Don't grant more powerful privileges than an account actually needs.
4. Implement input validation rules at the application layer to define what is considered valid user input before it reaches the database.
2. What are some best practices for securing SQL Server logins and users? (Please give at least 4 examples)
Here are 4 SQL Server
The document discusses database security and SQL injection attacks. It provides an overview of access control in SQL and MySQL, including the use of views and privileges. It then describes SQL injection attacks, giving examples of how attackers can exploit vulnerabilities to view sensitive data or delete tables. The best defense is using prepared statements with bound parameters rather than embedding user input directly into SQL. Other defenses include input validation, output encoding, limiting permissions, and configuring error reporting.
The document discusses database security and SQL injection attacks. It provides an overview of access control in SQL and MySQL, views, and limitations of SQL security. It defines SQL injection attacks and gives examples of how attacks work by inserting malicious SQL statements into user input. The document recommends best practices for prevention, including using prepared statements with bound variables, input validation, output encoding, and limiting database permissions.
The document discusses modern Android development best practices and libraries. It recommends using libraries like ButterKnife, Otto event bus, Retrofit, Dagger 2, and Picasso. It also discusses implementing Material Design principles and shared element transitions. The recommended design pattern is Model-View-Presenter. The document promotes two apps developed with these techniques.
Rethinking Kållered │ From Big Box to a Reuse Hub: A Transformation Journey ...SirmaDuztepeliler
"Rethinking Kållered │ From Big Box to a Reuse Hub: A Transformation Journey Toward Sustainability"
The booklet of my master’s thesis at the Department of Architecture and Civil Engineering at Chalmers University of Technology. (Gothenburg, Sweden)
This thesis explores the transformation of the vacated (2023) IKEA store in Kållered, Sweden, into a "Reuse Hub" addressing various user types. The project aims to create a model for circular and sustainable economic practices that promote resource efficiency, waste reduction, and a shift in societal overconsumption patterns.
Reuse, though crucial in the circular economy, is one of the least studied areas. Most materials with reuse potential, especially in the construction sector, are recycled (downcycled), causing a greater loss of resources and energy. My project addresses barriers to reuse, such as difficult access to materials, storage, and logistics issues.
Aims:
• Enhancing Access to Reclaimed Materials: Creating a hub for reclaimed construction materials for both institutional and individual needs.
• Promoting Circular Economy: Showcasing the potential and variety of reusable materials and how they can drive a circular economy.
• Fostering Community Engagement: Developing spaces for social interaction around reuse-focused stores and workshops.
• Raising Awareness: Transforming a former consumerist symbol into a center for circular practices.
Highlights:
• The project emphasizes cross-sector collaboration with producers and wholesalers to repurpose surplus materials before they enter the recycling phase.
• This project can serve as a prototype for reusing many idle commercial buildings in different scales and sizes.
• The findings indicate that transforming large vacant properties can support sustainable practices and present an economically attractive business model with high social returns at the same time.
• It highlights the potential of how sustainable practices in the construction sector can drive societal change.
RPWORLD offers custom injection molding service to help customers develop products ramping up from prototypeing to end-use production. We can deliver your on-demand parts in as fast as 7 days.
2. Android Persistent Data Storage Douglas C. Schmidt
2
Data Storage Options on Android
• Android offers several ways to store
data
• SQLite database
• Files
• SharedPreferences
4. Android Persistent Data Storage Douglas C. Schmidt
4
Learning Objectives in this Part of the Module
• Understand what SQLite is & how to use it in Android
5. Android Persistent Data Storage Douglas C. Schmidt
5
Android SQLite
• Android supports SQLite, which provides
a relational database for a mobile device
• i.e., it contains tables (consisting of
rows & columns), indexes, etc. that
form a “schema”
www.drdobbs.com/database/using-sqlite-on-android/232900584
6. Android Persistent Data Storage Douglas C. Schmidt
6
Android SQLite
• Android supports SQLite, which provides
a relational database for a mobile device
• It’s designed to operate within a
small footprint (~350kB) within
a single cross-platform disk file
en.wikipedia.org/wiki/SQLite
7. Android Persistent Data Storage Douglas C. Schmidt
7
Android SQLite
• Android supports SQLite, which provides
a relational database for a mobile device
• It’s designed to operate within a
small footprint (<300kB) within
a single cross-platform disk file
• Implements most of SQL92 &
supports so-called “ACID”
transactions
• Atomic, Consistent, Isolated, & Durable
en.wikipedia.org/wiki/SQL-92
8. Android Persistent Data Storage Douglas C. Schmidt
8
Android SQLite
• Android supports SQLite, which provides
a relational database for a mobile device
• It’s designed to operate within a
small footprint (<300kB) within
a single cross-platform disk file
• Implements most of SQL92 &
supports so-called “ACID”
transactions
• Access to an SQLite database typically
involves accessing the Android filesystem
• Database operations are typically
asynchronous since filesystem access
can be slow
• e.g., access is often made via AsyncTask,
AsyncQueryHandler, CursorLoader, etc.
www.vogella.com/articles/AndroidSQLite/article.html
9. Android Persistent Data Storage Douglas C. Schmidt
9
SQLiteDatabase
• SQLiteDatabase is the base class
for working with a SQLite database
in Android
• It provides the insert(),
update(), & delete() methods
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
10. Android Persistent Data Storage Douglas C. Schmidt
10
SQLiteDatabase
• SQLiteDatabase is the base class
for working with a SQLite database
in Android
• It provides the insert(),
update(), & delete() methods
• It also provides the execSQL()
method that can execute an
SQL statement directly
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
11. Android Persistent Data Storage Douglas C. Schmidt
11
SQLiteDatabase
• SQLiteDatabase is the base class
for working with a SQLite database
in Android
• Queries can be created via
rawQuery() & query() methods or
via the SQLiteQueryBuilder class
developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html
12. Android Persistent Data Storage Douglas C. Schmidt
12
ContentValues
developer.android.com/reference/android/content/ContentValues.html
• The ContentValues object is used
by SQLiteDatabase to define
key/values
• The “key” represents the table
column identifier & the “value”
represents the content for the
table record in this column
13. Android Persistent Data Storage Douglas C. Schmidt
13
ContentValues
developer.android.com/reference/android/content/ContentValues.html
• The ContentValues object is used
by SQLiteDatabase to define
key/values
• ContentValues can be used for
inserts & updates of database
entries
14. Android Persistent Data Storage Douglas C. Schmidt
14
SQLiteOpenHelper
• Recommended means of using
SQLiteDatabase is to subclass the
SQLiteOpenHelper class
• In constructor call the super()
method of SQLiteOpenHelper,
specifying database name &
current database version
developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
15. Android Persistent Data Storage Douglas C. Schmidt
15
SQLiteOpenHelper
• Recommended means of using
SQLiteDatabase is to subclass the
SQLiteOpenHelper class
• In constructor call the super()
method of SQLiteOpenHelper,
specifying database name &
current database version
• Override onCreate(), which is
called by SQLite if the database
does not yet exist
• e.g., execute CREATE TABLE
command
developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
16. Android Persistent Data Storage Douglas C. Schmidt
16
SQLiteOpenHelper
• Recommended means of using
SQLiteDatabase is to subclass the
SQLiteOpenHelper class
• In constructor call the super()
method of SQLiteOpenHelper,
specifying database name &
current database version
• Override onCreate(), which is
called by SQLite if the database
does not yet exist
• Override onUpgrade(), which is
called if the database version
increases in App code to allow
database schema updates
developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
17. Android Persistent Data Storage Douglas C. Schmidt
17
SQLiteOpenHelper
• Recommended means of using
SQLiteDatabase is to subclass the
SQLiteOpenHelper class
• Use SQLiteOpenHelper methods to
open & return underlying database
• e.g., getReadableDatabase() &
getWriteableDatabase() to
access an SQLiteDatabase
object either in read or write
mode, respectively
developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
18. Android Persistent Data Storage Douglas C. Schmidt
18
Opening an SQLite Database
public class ArtistDatabaseHelper extends SQLiteOpenHelper {
final private static String CREATE_CMD =
"CREATE TABLE artists ("
+ "_id" + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "name" + " TEXT NOT NULL)";
public ArtistDatabaseHelper(Context context) {
super(context, "artists_db", null, 1);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_CMD);
}
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) { /* ... */ }
...
It’s common to create an SQLiteOpenHelper subclass for each SQL table
Create the SQL table
SQL commands to create a table of artists
Give a name to the table
Support schema evolution
19. Android Persistent Data Storage Douglas C. Schmidt
19
Using an SQLite Database Via an Activity
public class DatabaseExampleActivity extends ListActivity {
final static String[] columns ={"_id", "name"};
static SQLiteDatabase db = null;
public void onCreate(Bundle savedInstanceState) {
...
ArtistDatabaseHelper dbHelper =
new ArtistDatabaseHelper
(getActivity().getApplicationContext());
db = dbHelper.getWritableDatabase();
insertArtists();
deleteLadyGaga();
Cursor c = readArtists();
displayArtists(c);
}
...
SQLiteDatabase is often put in an App singleton to simplify access
Make the SQLiteOpenHelper subclass instance
Create a read/write databse
Perform various operations
20. Android Persistent Data Storage Douglas C. Schmidt
20
Inserting Values Into an SQLite Database
• Method for inserting a row into the database
public long insert (String table, String nullColHack, ContentValues values)
Parameters
table The table to insert the row into
nullColHack Optional (often null)
values Map containing initial col values for row; keys are col names
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
#insert(java.lang.String, java.lang.String, android.content.ContentValues)
21. Android Persistent Data Storage Douglas C. Schmidt
21
Inserting Values Into an SQLite Database
• Method for inserting a row into the database
public long insert (String table, String nullColHack, ContentValues values)
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
#insert(java.lang.String, java.lang.String, android.content.ContentValues)
22. Android Persistent Data Storage Douglas C. Schmidt
22
Inserting Values Into an SQLite Database
private void insertArtists() {
ContentValues values = new ContentValues();
values.put("name", "Lady Gaga");
db.insert("artists", null, values);
values.clear();
values.put("name", "Johnny Cash");
db.insert("artists", null, values);
values.clear();
values.put("name", "Sting");
db.insert("artists", null, values);
...
}
“key” represents the table column identifier & the “value”
represents the content for the table record in this column
23. Android Persistent Data Storage Douglas C. Schmidt
23
Deleting a Row From an SQLite Database
Parameters
table the table to delete from
whereClause optional WHERE clause to apply when deleting
whereArgs Passing null deletes all rows
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
#delete(java.lang.String, java.lang.String, java.lang.String[])
• Method for deleting row(s) from the database
public int delete(String table, String whereClause, String[] whereArgs)
24. Android Persistent Data Storage Douglas C. Schmidt
24
Deleting a Row From an SQLite Database
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
#delete(java.lang.String, java.lang.String, java.lang.String[])
• Method for deleting row(s) from the database
public int delete(String table, String whereClause, String[] whereArgs)
25. Android Persistent Data Storage Douglas C. Schmidt
25
Deleting a Row From an SQLite Database
private int deleteLadyGaga() {
return db.delete("artists",
"name" + "=?",
new String []
{"Lady Gaga"});
}
Remove Lady Gaga from the database of artists
Note the use of
the “whereArgs”
26. Android Persistent Data Storage Douglas C. Schmidt
26
Querying an SQLite Database
• You can use rawQuery() or a query() on an SQLiteDatabase
public Cursor rawQuery(String sql, String[] selectionArgs)
Runs the provided SQL and returns a Cursor over the result set
Parameters
Returns
A Cursor object, which is positioned before the first entry
sql the SQL query. The SQL string must not be ; terminated
selectionArgs You may include ?’s in where clause in the query, which are
replaced by the values from selectionArgs (the values will be
bound as Strings)
Cursors aren’t synchronized, see documentation for details
27. Android Persistent Data Storage Douglas C. Schmidt
27
Querying an SQLite Database
• You can use rawQuery() or a query() on an SQLiteDatabase
public Cursor query(String table, String[] columns, String selection, String[]
selectionArgs, String groupBy, String having, String orderBy)
query() builds up a SQL SELECT statement from its component parts
Parameter
String table The table name to compile the query against
int[] columns A list of which table columns to return ("null" returns all columns)
String selection Where-clause filters for the selection of data (null selects all data)
String[]
selectionArgs
You may include ?s in the “selection” where-clause that get replaced
by the values from the selectionArgs array
String[] groupBy A filter declaring how to group rows (null means rows not grouped)
String[] having Filter for the groups (null means no filter)
String[] orderBy Table columns used to order the data (null means no ordering)
Returns
A Cursor object, which is positioned before the first entry
28. Android Persistent Data Storage Douglas C. Schmidt
28
Using Query() vs. rawQuery()
private Cursor readArtists() {
// returns all rows
return db.rawQuery("SELECT _id, name FROM artists", null);
}
• Using rawQuery() on an SQLiteDatabase
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
#rawQuery(java.lang.String, java.lang.String[])
29. Android Persistent Data Storage Douglas C. Schmidt
29
Using Query() vs. rawQuery()
private Cursor readArtists() {
// returns all rows
return db.query("artists", new String [] {"_id", "name"},
null, null, null, null, null);
}
private Cursor readArtists() {
// returns all rows
return db.rawQuery("SELECT _id, name FROM artists", null);
}
• Using rawQuery() on an SQLiteDatabase
• Using query() on an SQLiteDatabase
developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
#query(java.lang.String, java.lang.String[], java.lang.String, java.lang.String[],
java.lang.String, java.lang.String, java.lang.String)
30. Android Persistent Data Storage Douglas C. Schmidt
30
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• This allows buffering of query
results efficiently since all data
needn’t be loaded into memory
31. Android Persistent Data Storage Douglas C. Schmidt
31
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• getCount() returns # of elements
of the resulting query
32. Android Persistent Data Storage Douglas C. Schmidt
32
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• getCount() returns # of elements
of the resulting query
• moveToFirst() & moveToNext()
move between individual data rows
33. Android Persistent Data Storage Douglas C. Schmidt
33
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• getCount() returns # of elements
of the resulting query
• moveToFirst() & moveToNext()
move between individual data rows
• isAfterLast() checks if the end of
the query result has been reached
34. Android Persistent Data Storage Douglas C. Schmidt
34
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• getCount() returns # of elements
of the resulting query
• moveToFirst() & moveToNext()
move between individual data rows
• isAfterLast() checks if the end of
the query result has been reached
• Provides typed get*() methods
• e.g., getLong(columnIndex) &
getString(columnIndex) to access
column data for current position
of result
35. Android Persistent Data Storage Douglas C. Schmidt
35
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• getCount() returns # of elements
of the resulting query
• moveToFirst() & moveToNext()
move between individual data rows
• isAfterLast() checks if the end of
the query result has been reached
• Provides typed get*() methods
• Provides getColumnIndexOrThrow
(String) to get column index for a
column name of table
36. Android Persistent Data Storage Douglas C. Schmidt
36
Cursor Iterators
developer.android.com/reference/android/database/Cursor.html
• Query() returns a Cursor Iterator
that represents result of a query &
points to one row of query result
• getCount() returns # of elements
of the resulting query
• moveToFirst() & moveToNext()
move between individual data rows
• isAfterLast() checks if the end of
the query result has been reached
• Provides typed get*() methods
• Provides getColumnIndexOrThrow
(String) to get column index for a
column name of table
• Must be closed via close()
37. Android Persistent Data Storage Douglas C. Schmidt
37
Displaying an SQLite Database
private void displayArtists (Cursor c) {
setListAdapter(
new SimpleCursorAdapter
(this, R.layout.list_layout, c,
new String [] {"_id", "name"},
new int[] { R.id._id, R.id.name }));
}
developer.android.com/reference/android/widget/SimpleCursorAdapter.html
• The SimpleCursorAdapter class maps the
columns to the Views based on
the Cursor passed to it
38. Android Persistent Data Storage Douglas C. Schmidt
38
Examining an SQLite Database
• If your App creates a database it is saved by default in a directory file
/DATA/data/APP_NAME/databases/FILENAME
• DATA is the path that the Environment. getDataDirectory() method returns
• APP_NAME is your app name
• FILENAME is the name you specify in your application code for the
database
39. Android Persistent Data Storage Douglas C. Schmidt
39
Examining an SQLite Database
• If your App creates a database it is saved by default in a directory file
• You can examine this database with sqlite3
# adb shell
# sqlite3 /data/data/com.android.launcher/databases/launcher.db
40. Android Persistent Data Storage Douglas C. Schmidt
40
Summary
• SQLite is embedded into every Android device
• Using an SQLite database in Android does not require a setup procedure or
administration of the database
41. Android Persistent Data Storage Douglas C. Schmidt
41
Summary
• SQLite is embedded into every Android device
• You only have to define the SQL statements for creating & updating the
database
• Afterwards the database is automatically managed for you by the Android
platform
43. Developing Android Apps with Eclipse Douglas C. Schmidt
43
Overview of Content Providers
• ContentProviders manage access to a central
repository of structured data & can make an
App’s data available to other Apps
developer.android.com/guide/topics/providers/content-providers.html
44. Developing Android Apps with Eclipse Douglas C. Schmidt
44
Overview of Content Providers
• ContentProviders manage access to a central
repository of structured data & can make an
App’s data available to other Apps
• They encapsulate the data & provide
mechanisms for defining data security
developer.android.com/guide/topics/providers/content-providers.html
45. Developing Android Apps with Eclipse Douglas C. Schmidt
45
Overview of Content Providers
• ContentProviders manage access to a central
repository of structured data & can make an
App’s data available to other Apps
• They encapsulate the data & provide
mechanisms for defining data security
• Content providers are the standard interface
that connects data in one process with code
running in another process
developer.android.com/guide/topics/providers/content-providers.html
46. Developing Android Apps with Eclipse Douglas C. Schmidt
46
Overview of Content Providers
• ContentProviders manage access to a central
repository of structured data & can make an
App’s data available to other Apps
• They encapsulate the data & provide
mechanisms for defining data security
• Content providers are the standard interface
that connects data in one process with code
running in another process
• Content providers support database “CRUD”
operations (Create, Read, Update, Delete),
where “read” is implemented as “query”
developer.android.com/guide/topics/providers/content-providers.html
47. Developing Android Apps with Eclipse Douglas C. Schmidt
47
Overview of Content Providers
• ContentProviders manage access to a central
repository of structured data & can make an
App’s data available to other Apps
• They encapsulate the data & provide
mechanisms for defining data security
• Content providers are the standard interface
that connects data in one process with code
running in another process
• Content providers support database “CRUD”
operations (Create, Read, Update, Delete),
where “read” is implemented as “query”
• Apps can provide Activities that allow
users to query & modify the data managed
by a provider
developer.android.com/guide/topics/providers/content-providers.html
48. Developing Android Apps with Eclipse Douglas C. Schmidt
48
Example Android ContentProviders
• Android itself includes many Content
Providers that manage data for
• Browser – bookmarks, history
• Call log – telephone usage
• Contacts – contact data
• MMS/SMS – Stores messages sent
& received
• Media – media database
• UserDictionary – database for
predictive spelling
• Maps – previous searches
• YouTube – previous searches
• Many more
developer.android.com/reference/android/provider/package-summary.html
49. Developing Android Apps with Eclipse Douglas C. Schmidt
49
ContentProvider Data Model
• A content provider typically
presents data to external
Apps as one or more tables
• e.g., the tables found in
a relational SQL
database
50. Developing Android Apps with Eclipse Douglas C. Schmidt
50
ContentProvider Data Model
• A content provider typically
presents data to external
Apps as one or more tables
• A row represents an
instance of some type of
data the provider collects
• Each column in a row
represents an individual
piece of data collected
for an instance
word app id freq locale _ID
mapreduce user1 100 en_US 1
precompiler user14 200 fr_FR 2
applet user2 225 fr_CA 3
const user1 255 pt_BR 4
int user5 100 en_UK 5
One provider in Android is the
user dictionary, which stores the
spellings of non-standard words
that the user wants to keep
51. Developing Android Apps with Eclipse Douglas C. Schmidt
51
Overview of ContentResolver
• ContentProvider never accessed
directly, but accessed indirectly
via a ContentResolver
• ContentProvider not created
until a ContentResolver tries
to access it
developer.android.com/reference/android/content/ContentResolver.html
52. Developing Android Apps with Eclipse Douglas C. Schmidt
52
Overview of ContentResolver
• ContentProvider never accessed
directly, but accessed indirectly
via a ContentResolver
• ContentResolvers manage &
support ContentProviders
• Enables use of ContentProviders
across multiple Apps
developer.android.com/reference/android/content/ContentResolver.html
53. Developing Android Apps with Eclipse Douglas C. Schmidt
53
Overview of ContentResolver
• ContentProvider never accessed
directly, but accessed indirectly
via a ContentResolver
• ContentResolvers manage &
support ContentProviders
• Enables use of ContentProviders
across multiple Apps
• Provides additional services, such
as change notification & IPC
developer.android.com/reference/android/content/ContentResolver.html
54. Developing Android Apps with Eclipse Douglas C. Schmidt
54
Overview of ContentResolver
• ContentProvider never accessed
directly, but accessed indirectly
via a ContentResolver
• ContentResolvers manage &
support ContentProviders
• Context.getContentResolver()
accesses default ContentResolver
ContentResolver cr =
getContentResolver();
developer.android.com/reference/android/content/ContentResolver.html
55. Developing Android Apps with Eclipse Douglas C. Schmidt
55
• When you query data via a
ContentProvider, you don't
communicate with the provider
directly
• Instead, you use a
ContentResolver object to
communicate with the provider
ContentResolver vs. ContentProvider
www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html
56. Developing Android Apps with Eclipse Douglas C. Schmidt
56
ContentResolver vs. ContentProvider
• When you query data via a
ContentProvider, you don't
communicate with the provider
directly
• A call to getContentResolver().
query() is made
• This method call invokes
ContentResolver.query(), not
ContentProvider.query()
www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html
57. Developing Android Apps with Eclipse Douglas C. Schmidt
57
ContentResolver vs. ContentProvider
• When you query data via a
ContentProvider, you don't
communicate with the provider
directly
• A call to getContentResolver().
query() is made
• When this query method is
invoked, the Content Resolver
parses the uri argument & extracts
its authority
• The Content Resolver directs the
request to the content provider
registered with the (unique)
authority by calling the Content
Provider's query() method
www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html
58. Developing Android Apps with Eclipse Douglas C. Schmidt
58
ContentResolver vs. ContentProvider
• When you query data via a
ContentProvider, you don't
communicate with the provider
directly
• A call to getContentResolver().
query() is made
• When this query method is invoked,
the Content Resolver parses the uri
argument & extracts its authority
• When the Content Provider's query()
method is invoked, the query is
performed & a Cursor is returned (or
an exception is thrown)
• The resulting behavior depends on
Content Provider's implementation
www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html
59. Developing Android Apps with Eclipse Douglas C. Schmidt
59
Content URIs
• Any URI that begins with the content://
scheme represents a resource served up
by a Content Provider
60. Developing Android Apps with Eclipse Douglas C. Schmidt
60
Content URIs
• Any URI that begins with the content://
scheme represents a resource served up
by a Content Provider
• e.g., content://authority/path/id
• content - data is managed by a
ContentProvider
61. Developing Android Apps with Eclipse Douglas C. Schmidt
61
Content URIs
• Any URI that begins with the content://
scheme represents a resource served up
by a Content Provider
• e.g., content://authority/path/id
• content - data is managed by a
ContentProvider
• authority – id for the content provider
62. Developing Android Apps with Eclipse Douglas C. Schmidt
62
Content URIs
• Any URI that begins with the content://
scheme represents a resource served up
by a Content Provider
• e.g., content://authority/path/id
• content - data is managed by a
ContentProvider
• authority – id for the content provider
• path – 0 or more segments indicating
the type of data to access
63. Developing Android Apps with Eclipse Douglas C. Schmidt
63
Content URIs
• Any URI that begins with the content://
scheme represents a resource served up
by a Content Provider
• e.g., content://authority/path/id
• content - data is managed by a
ContentProvider
• authority – id for the content provider
• path – 0 or more segments indicating
the type of data to access
• id – specific record being requested
64. Developing Android Apps with Eclipse Douglas C. Schmidt
64
Content URIs
• Any URI that begins with the content://
scheme represents a resource served up
by a Content Provider
• e.g., content://authority/path/id
• ContentProviders are a façade that
offers data encapsulation via Content
Uri objects used as handles
• The data could be stored in a SQLite
database, in flat files, retrieved off a
device, be stored on some server
accessed over the Internet, etc.
65. Developing Android Apps with Eclipse Douglas C. Schmidt
65
Inserting Data Via ContentResolver
• Use ContentResolver.insert() to insert data into a ContentProvider
public final Uri insert(Uri uri, ContentValues values)
• Inserts a row into a table at the given URI
• If the content provider supports transactions the insertion will be atomic
Parameters
• uri – The uri of the table to insert into
• values – The initial values for the newly inserted row, where the key is
the column name for the field (passing an empty ContentValues will
create an empty row)
Returns
• the URI of the newly created row
developer.android.com/reference/android/content/ContentProvider.html
#insert(android.net.Uri, android.content.ContentValues)
66. Developing Android Apps with Eclipse Douglas C. Schmidt
66
Deleting Data Via ContentResolver
• Use ContentResolver.delete() to delete data from a ContentProvider
public final int delete(Uri uri, String where, String[] selectionArgs)
• Deletes row(s) specified by a content URI. If the content provider
supports transactions, the deletion will be atomic
Parameters
• uri – The uri of the row to delete
• where – A filter to apply to rows before deleting, formatted as an SQL
WHERE clause (excluding the WHERE itself)
• selectionArgs – SQL pattern args
Returns
• The number of rows deleted
developer.android.com/reference/android/content/ContentProvider.html
#delete(android.net.Uri, java.lang.String, java.lang.String[])
67. Developing Android Apps with Eclipse Douglas C. Schmidt
67
Inserting/Deleting via applyBatch()
• ContentResolver.applyBatch() can insert (& delete) groups of data
public ContentProviderResult[] applyBatch (String authority,
ArrayList<ContentProviderOperation> operations)
• Applies each ContentProviderOperation object & returns array of results
• If all the applications succeed then a ContentProviderResult array with the
same number of elements as the operations will be returned
Parameters
• authority –authority of the ContentProvider to apply this batch
• operations – the operations to apply
Returns
• the results of the applications
developer.android.com/reference/android/content/ContentProvider.html
#applyBatch(java.util.ArrayList<android.content.ContentProviderOperation>)
68. Developing Android Apps with Eclipse Douglas C. Schmidt
68
Querying a ContentResolver
• Use ContentResolver. query()
to retrieve data
• Returns a Cursor instance
for accessing results
• A Cursor is an iterator over
a result set
developer.android.com/reference/android/content/ContentProvider.html#query
(Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)
69. Developing Android Apps with Eclipse Douglas C. Schmidt
69
query() Parameters Compared to SQL Query
query()
argument
SELECT
keyword/parameter
Notes
Uri FROM table_name Uri maps to the table in the provider
named table_name
projection col,col,col,... projection is an array of columns that
should be included for each row
retrieved
selection WHERE col =value selection specifies the criteria for
selecting rows
selectionArgs No exact equivalent in
SQL
Selection arguments replace the ?
placeholders in the selection clause
sortOrder ORDER BYcol,col,... sortOrder specifies the order in which
rows appear in the returned Cursor
70. Developing Android Apps with Eclipse Douglas C. Schmidt
70
Summary
• A SQLite database is private to the
App which creates it
• If you want to share data with other
App you can use a content provider
71. Developing Android Apps with Eclipse Douglas C. Schmidt
71
Summary
• A SQLite database is private to the
App which creates it
• A content provider allows App to
access data
• In most cases this data is stored
in an SQlite database
72. Developing Android Apps with Eclipse Douglas C. Schmidt
72
Summary
• A SQLite database is private to the
App which creates it
• A content provider allows App to
access data
• While a content provider can be used
within an App to access data, its is
typically used to share data with other
App
73. Developing Android Apps with Eclipse Douglas C. Schmidt
73
Summary
• A SQLite database is private to the
App which creates it
• A content provider allows App to
access data
• While a content provider can be used
within an App to access data, its is
typically used to share data with other
App
• App data is by default private, so a
content provider is a convenient to
share you data with other application
based on a structured interface
74. Developing Android Apps with Eclipse Douglas C. Schmidt
74
Summary
• A SQLite database is private to the
App which creates it
• A content provider allows App to
access data
• While a content provider can be used
within an App to access data, its is
typically used to share data with other
App
• App data is by default private, so a
content provider is a convenient to
share you data with other application
based on a structured interface
• A content provider must be declared
in the AndroidManifest.xml file