Android SQLite

From HaFrWiki
Jump to: navigation, search

Almost every app needs to store data. On Android there are several options to to do so, one of them is the SQLIte option discussed on this page.

Introduction

The usage of Android SQLite databases is simplified using the SQLiteOpenHelper class. Usage is not complex but if not familiar with the solution you may wonder how to use this class.


SQLIteOpenHelper

The SQLIteOpenHelper class is an abstract class and therefor it needs to be extended. Further more the constructor has 4 parameters:

  • Context context, Context to use to open or create the database. This is created in the application as the activity (getActivity)
  • String name, The name of the database.
  • SQLiteDatabase.CursorFactory factory, The factory to use for creating cursor objects, or null for the default.
  • int version, The number of the database (starting at 1).
    • If the database is older, onUpgrade(SQLiteDatabase, int, int) will be used to upgrade the database.
    • If the database is newer, onDowngrade(SQLiteDatabase, int, int) will be used to downgrade the database.

Tutorials

top

Q&A

top

Examples

top

See also

top

Reference

top