Ch4
W24
Create a user registration application that stores the user details in a SQLite database table.7
Explain Content Provider with example. 04
Explain about saving data to internal and external storage. 04
W23
What are the different ways to store Data in Android? 03
(b) Give brief idea about Internal versus External storage. 04
(c) Write a code to insert into product_detail (prod_id, prod_name, prod_rate) in SQLite
database using Android. 07
List down the Advantage and Disadvantage of SQLite Database. 07
W22
Develop an application to store student details like roll no, name, branch, marks, percentage
and retrieve student information using roll no. in SQLite databases. 07
Explain SQLiteOpenHelper class. 04
S24
Briefly explain: Content Provider in Android. 04
Demonstrate the use of SQLite database in Android App with an example. 07
What is the significance of Shared preferences in Android? 03
S23
Design Android App having facility of student registration. (Use SQLite database.) 07
What is the use of Content Provider in Android? 04
(c) Design Android App having facility of login. (Use SQLite database.) 07
Briefly explain: Shared preferences 03
S22
Make Application for student’s registration of basic details like Enrollment No, Name,
Branch, Address, Mobile Number, Email Id. 07
Explain SQLite Database and why it is required. 03
(b) Explain Content Provider. 04
✅ A. SQLite-Based Applications (7 Marks Each)
1. User/Student Registration & Retrieval
W24:
Create a user registration application that stores the user details in a SQLite database
table.
W22:
Develop an application to store student details like roll no, name, branch, marks,
percentage and retrieve student information using roll no. in SQLite databases.
S23 / S22:
Design Android App having facility of student registration. (Use SQLite database.)
Make Application for student’s registration of basic details like Enrollment No, Name,
Branch, Address, Mobile Number, Email Id.
2. Insertion / Login Functionality
W23:
Write a code to insert into product_detail (prod_id, prod_name, prod_rate) in SQLite
database using Android.
S23:
Design Android App having facility of login. (Use SQLite database.)
S24:
Demonstrate the use of SQLite database in Android App with an example.
✅ B. Content Provider (4 Marks Each)
W24:
Explain Content Provider with example.
S24 / S23 / S22:
Briefly explain: Content Provider in Android.
What is the use of Content Provider in Android?
Explain Content Provider.
✅ C. Data Storage in Android
1. Storage Methods and Differences
W23:
(a) What are the different ways to store Data in Android? (03)
(b) Give brief idea about Internal versus External storage. (04)
W24:
Explain about saving data to internal and external storage. (04)
S22:
Explain SQLite Database and why it is required. (03)
2. Shared Preferences
S24 / S23:
What is the significance of Shared preferences in Android? (03)
Briefly explain: Shared preferences (03)
✅ D. SQLiteOpenHelper Class
W22:
Explain SQLiteOpenHelper class. (04)
✅ E. SQLite Advantages and Disadvantages
W23:
List down the Advantage and Disadvantage of SQLite Database. (07)
Here are the detailed answers to your questions, structured for academic or exam writing:
✅ A. What is the significance of SharedPreferences in Android? (03 Marks)
SharedPreferences is a lightweight mechanism in Android used to store and retrieve key-
value pairs of primitive data types such as int, boolean, float, long, and String. It is
commonly used for saving user preferences, settings, or flags like login status.
✦ Significance:
Persistence: Data remains stored even after the application is closed.
Simplicity: Easy to use for saving and retrieving small amounts of data.
Efficiency: Consumes minimal memory and storage.
Use Cases: Theme selection, remember-me features, first-time launch detection.
✅ B. Briefly explain: SharedPreferences (03 Marks)
SharedPreferences is an Android API used to store simple configuration data as key-value
pairs.
✦ How it Works:
You access it using getSharedPreferences() method.
Modify data using SharedPreferences.Editor.
Data is stored in an XML file within internal storage.
✦ Example:
SharedPreferences sp = getSharedPreferences("MyPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("username", "John");
editor.putBoolean("loggedIn", true);
editor.apply();
✦ Methods:
putString(), putBoolean(), putInt() – to write
getString(), getBoolean() – to read
✅ C. Explain SQLiteOpenHelper Class. (04 Marks)
SQLiteOpenHelper is an abstract helper class provided by Android that simplifies database
creation and version management.
✦ Purpose:
Helps manage database creation, upgrades, and version control.
Avoids manual handling of SQLiteDatabase objects and version changes.
✦ Key Methods:
1. onCreate(SQLiteDatabase db)
o Called when the database is created for the first time.
o Use it to define table creation statements.
2. onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
o Called when the database needs to be upgraded.
o Used for schema migration.
✦ Example:
public class MyDatabaseHelper extends SQLiteOpenHelper {
public MyDatabaseHelper(Context context) {
super(context, "StudentDB", null, 1);
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE student(id INTEGER PRIMARY KEY, name TEXT)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS student");
onCreate(db);
✅ D. Advantages and Disadvantages of SQLite Database. (07 Marks)
✦ Advantages:
1. Lightweight: It doesn’t require any setup or separate server.
2. Built-in: Included in Android by default.
3. Fast Access: Efficient for reading and writing local data.
4. Relational Support: Supports SQL queries with multiple tables.
5. Zero Configuration: Easy to set up and use.
6. Open Source: Free to use and modify.
7. Reliable: ACID-compliant (Atomicity, Consistency, Isolation, Durability).
✦ Disadvantages:
1. Limited for Large-scale Applications: Not suitable for apps with very complex data
needs.
2. No Concurrent Access: Multiple processes accessing the database simultaneously
can cause issues.
3. Security: Requires additional layers for encryption and security.
4. Boilerplate Code: Requires considerable boilerplate without abstraction layers like
Room.
5. Manual Migration: Schema upgrades need to be handled manually.
6. No Server Features: No built-in support for stored procedures, triggers, or remote
access.
7. Data Redundancy Risk: Poor design can lead to redundancy without enforced
normalization.
Would you like this compiled into a formatted Word or PDF document for study or
submission purposes?
Here is a complete Android App that performs student registration using SQLite database,
including:
A form to collect:
o Enrollment No
o Name
o Branch
o Address
o Mobile Number
o Email ID
A button to submit the form and store data in the local database.
A button to view all registered students (basic display).
✅ Project Structure
com.example.studentregistration
├── MainActivity.java
├── Student.java
├── DBHelper.java
└── activity_main.xml
1. activity_main.xml
<!-- res/layout/activity_main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/enroll"
android:hint="Enrollment No"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/name"
android:hint="Name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/branch"
android:hint="Branch"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/address"
android:hint="Address"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/mobile"
android:hint="Mobile Number"
android:inputType="phone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/email"
android:hint="Email ID"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_register"
android:text="Register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"/>
<Button
android:id="@+id/btn_view"
android:text="View Students"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
</LinearLayout>
</ScrollView>
2. MainActivity.java
package com.example.studentregistration;
import android.app.AlertDialog;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText enroll, name, branch, address, mobile, email;
Button btnRegister, btnView;
DBHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enroll = findViewById(R.id.enroll);
name = findViewById(R.id.name);
branch = findViewById(R.id.branch);
address = findViewById(R.id.address);
mobile = findViewById(R.id.mobile);
email = findViewById(R.id.email);
btnRegister = findViewById(R.id.btn_register);
btnView = findViewById(R.id.btn_view);
db = new DBHelper(this);
btnRegister.setOnClickListener(v -> {
boolean inserted = db.insertStudent(
enroll.getText().toString(),
name.getText().toString(),
branch.getText().toString(),
address.getText().toString(),
mobile.getText().toString(),
email.getText().toString()
);
Toast.makeText(this,
inserted ? "Student Registered" : "Registration Failed",
Toast.LENGTH_SHORT).show();
});
btnView.setOnClickListener(v -> {
Cursor res = db.getAllStudents();
if (res.getCount() == 0) {
showMessage("Error", "No records found");
return;
StringBuilder buffer = new StringBuilder();
while (res.moveToNext()) {
buffer.append("Enrollment No: ").append(res.getString(0)).append("\n")
.append("Name: ").append(res.getString(1)).append("\n")
.append("Branch: ").append(res.getString(2)).append("\n")
.append("Address: ").append(res.getString(3)).append("\n")
.append("Mobile: ").append(res.getString(4)).append("\n")
.append("Email: ").append(res.getString(5)).append("\n\n");
showMessage("Student Records", buffer.toString());
});
}
private void showMessage(String title, String message) {
new AlertDialog.Builder(this)
.setCancelable(true)
.setTitle(title)
.setMessage(message)
.show();
3. DBHelper.java
package com.example.studentregistration;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.*;
public class DBHelper extends SQLiteOpenHelper {
public static final String DB_NAME = "StudentDB.db";
public static final String TABLE_NAME = "students";
public static final String COL1 = "enroll";
public static final String COL2 = "name";
public static final String COL3 = "branch";
public static final String COL4 = "address";
public static final String COL5 = "mobile";
public static final String COL6 = "email";
public DBHelper(Context context) {
super(context, DB_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +
COL1 + " TEXT PRIMARY KEY, " +
COL2 + " TEXT, " +
COL3 + " TEXT, " +
COL4 + " TEXT, " +
COL5 + " TEXT, " +
COL6 + " TEXT)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
public boolean insertStudent(String enroll, String name, String branch, String address,
String mobile, String email) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COL1, enroll);
values.put(COL2, name);
values.put(COL3, branch);
values.put(COL4, address);
values.put(COL5, mobile);
values.put(COL6, email);
long result = db.insert(TABLE_NAME, null, values);
return result != -1;
public Cursor getAllStudents() {
SQLiteDatabase db = this.getReadableDatabase();
return db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
✅ Expected Output:
When you open the app:
You will see a form with these fields:
Enrollment No
Name
Branch
Address
Mobile Number
Email ID
And two buttons: Register and View Students
On Register:
A toast:
✅ "Student Registered"
On View Students:
A dialog with data like:
Enrollment No: 101
Name: John Doe
Branch: CSE
Address: 123 Main St
Mobile: 9876543210
Email: john@example.com
Would you like to extend this to include Update/Delete features (full CRUD)?