![]() This tutorial assumes that you have already basic knowledge in Android development. Both activities will be communicating via Intents. The application will consists out of two activities, one for seeing a list of all todo items and one forcreating / maintaining a specific todo. ![]() These items will be stored inthe SQLite database. We will create a Todo application which allow the user to maintain items which should be done. Please see the ListView Tutorial for details. Via the method isAfterLast() you cancheck if there is still some data.Ī Cursor can be directly used via the "SimpleCursorAdapter" in ListViews. To move betweenindividual data rows, you can use the methods moveToFirst() and moveToNext(). ![]() To get the number of elements use the method getCount(). A query returns always a "Cursor".Ī Cursor represents the result of a query. SQLightBuilder is similar to the interface of an content provider therefore it istypically used for them. Queries can be created via the method rawQuery() which accepts SQL, query() which provides an interface for specifyingdynamic data or SQLightQueryBuilder. "SQLightDatabase" provides the methods insert(), update() and delete(). The database is represented by an "SQLightDatabase" object.įor the primary key of the database you should always use the identifier "_id" as some of Android functions rely on thisstandard. It also provides the methods getReadableDatabase() and getWriteableDatabase() to get access to the database either inread or write mode. "SQLightDatabase" provides the execSQL() method which allows to execute SQL. Both methods receive an "SQLightDatabase" object. In this class youneed to override the methods onCreate() to create the database and onUpgrade to upgrade the database in case of changesin the database schema. To create and upgrade a database in your Android application you usually subclass "SQLightOpenHelper". "DATA" is the path which Environment.getDataDirectory() returns,"APP_NAME" is your application name and "FILENAME" is the name you give the database during () usually return the SD card as location. If your application creates an database this database is saved in the directory"DATA/data/APP_NAME/databases/FILENAME". SQLight itselfdoes not validate if the types written to the columns are actually of the defined type, you can write an integer into a string All other types must be converted into on of these fields before saving them in the database. SQLite supports the data types TEXT (similar to String in Java), INTEGER (similar to long in Java) and REAL (similar todouble in Java). Please see Android Background Processing Tutorial for details. Therefore is it recommended to perform this taskin an AsyncTask. Working with databases in Android can be slow due to the necessary I/O. You specify the SQL for working with thedatabase and the database is automatically managed for you. Using SQLite in Android does not require any database setup or administration. In addition it requires only little memory at runtime (approx.250 KByte). SQLight supports standard relational databasefeatures like SQL syntax, transactions and prepared statements. SQLite is an Open Source Database which is embedded into Android. The tutorial is based on Eclipse 3.6, Java1.6 and Android 2.3 (Gingerbread).ġ.1. This tutorial describes how to use the SQLite database in Android applications. Revision HistoryRevision 0.1 Lars VogelCreatedRevision 0.2 - 1.2 - Lars Vogelbug fixes and enhancements SQLight itself does not validate if the types written to the columns are actually of the defined type, you can write an integer into a string Android SQLite Database - Tutorial 1. SQLite supports the data types TEXT (similar to String in Java), INTEGER (similar to long in Java) and REAL (similar to double in Java). Therefore is it recommended to perform this task in an AsyncTask. ![]() You specify the SQL for working with the database and the database is automatically managed for you. In addition it requires only little memory at runtime (approx. SQLight supports standard relational database features like SQL syntax, transactions and prepared statements. SQLite in Android SQLite is an Open Source Database which is embedded into Android. The tutorial is based on Eclipse 3.6, Java 1.6 and Android 2.3 (Gingerbread). Lars Vogel Version 1.2 Copyright © 2011 Lars Vogel Revision History Revision 0.1 Lars Vogel Created Revision 0.2 - 1.2 - Lars Vogel bug fixes and enhancements Using the Android SQLite Database This tutorial describes how to use the SQLite database in Android applications.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |