[go: up one dir, main page]

0% found this document useful (0 votes)
21 views3 pages

SQLite in Android Notes

SQLite is a self-contained, serverless SQL database engine bundled with Android, ideal for local data storage in applications. It features lightweight setup, ACID compliance, and supports relational data structures, while being accessed through the android.database.sqlite package. Despite its advantages, SQLite has limitations such as lack of built-in encryption and limited concurrent access, with alternatives like Room and Realm available for more complex needs.

Uploaded by

manvi0318
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

SQLite in Android Notes

SQLite is a self-contained, serverless SQL database engine bundled with Android, ideal for local data storage in applications. It features lightweight setup, ACID compliance, and supports relational data structures, while being accessed through the android.database.sqlite package. Despite its advantages, SQLite has limitations such as lack of built-in encryption and limited concurrent access, with alternatives like Room and Realm available for more complex needs.

Uploaded by

manvi0318
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

What is SQLite Database in Android?

1. Introduction

SQLite is a self-contained, serverless, zero-configuration SQL database engine.

It is bundled with Android OS, so developers can use it without installing any additional libraries.

Commonly used for local data storage in Android applications.

Suitable for storing structured data, such as user details, app settings, history, or any relational data.

2. Features of SQLite in Android

- Lightweight: Minimal setup and consumes little memory and disk space.

- Integrated with Android: Comes pre-installed with the OS.

- Local storage: Stores data directly on the user's device.

- Transactional: Supports ACID properties.

- Relational Database: Supports tables, indexes, triggers, views.

- Cross-platform compatibility: Works across various platforms.

3. How SQLite Works in Android

- Accessed via android.database.sqlite package.

- Data is stored in .db file format.

- Managed using SQLiteOpenHelper class in Android.

4. Key Components in Android SQLite

a. SQLiteOpenHelper: Manages database creation and version management.

- onCreate(): Called when the database is first created.

- onUpgrade(): Called when the database version changes.

b. SQLiteDatabase: Performs CRUD operations such as insert(), update(), delete(), and query().

c. Cursor: Used to iterate over results from a query.

5. Example Use Case

public class MyDatabaseHelper extends SQLiteOpenHelper {


What is SQLite Database in Android?

public MyDatabaseHelper(Context context) {

super(context, "MyDatabase.db", null, 1);

@Override

public void onCreate(SQLiteDatabase db) {

db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email

TEXT)");

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

db.execSQL("DROP TABLE IF EXISTS users");

onCreate(db);

Usage:

MyDatabaseHelper dbHelper = new MyDatabaseHelper(context);

SQLiteDatabase db = dbHelper.getWritableDatabase();

6. Advantages of SQLite in Android

- Built-in and free: No extra libraries needed.

- Simple API: Beginner-friendly.

- Offline support: Works without internet.

- Data persistence: Data remains after app close or restart.

- Fast and efficient: Optimized for mobile devices.

7. Limitations of SQLite

- No built-in encryption.

- Single-user environment.
What is SQLite Database in Android?

- Limited concurrent access.

- No compile-time SQL verification.

- Difficult schema migration for complex apps.

8. Alternatives to SQLite

- Room Database: Easier abstraction with compile-time validation.

- Realm: Fast, object-oriented database.

- Firebase Realtime Database / Firestore: Cloud-based solutions.

- ObjectBox: High-performance NoSQL database.

9. Conclusion

SQLite is the default and common local storage method in Android.

It is best for lightweight, offline-capable apps.

Mastery of SQLite is essential for robust Android app development.

Room may be preferred for modern, scalable apps.

You might also like