TU BCA Mobile Programming Master Guide: Android Activity Lifecycle, Intents & SQLite Database (Complete Lab Code)
Author: Bhuban Subedi | Subject: Mobile Programming (CACS351) | Semester: Sixth Semester
With billions of active smartphones globally, native mobile application engineering is one of the highest-demand skills in software development. In the Tribhuvan University BCA sixth semester, Mobile Programming (CACS351) trains students in Android platform architecture, XML/Jetpack UI layout design, Activity lifecycle management, inter-component communication through Intents, and local SQLite database persistence.
In the final 60-mark TU board examination and the 40-mark external laboratory viva, examiners consistently test the Android Activity Lifecycle State Transitions, Explicit vs. Implicit Intents, and writing end-to-end SQLite CRUD applications using SQLiteOpenHelper.
In this guide, I will provide production-grade Java code and architectural diagrams for TU exam success.
1. Android Platform Architecture
+-------------------------------------------------------------------------------+
| APPLICATIONS LAYER |
| (Dialer, SMS, Web Browser, Custom TU BCA BCA Notes App) |
+-------------------------------------------------------------------------------+
| APPLICATION FRAMEWORK LAYER |
| Activity Manager | Window Manager | Content Providers | Notification Manager |
+-------------------------------------------------------------------------------+
| LIBRARIES & ANDROID RUNTIME (ART) |
| WebKit | OpenGL ES | SQLite | FreeType | ART (Ahead-Of-Time Comp & GC) |
+-------------------------------------------------------------------------------+
| HARDWARE ABSTRACTION LAYER (HAL) |
| Camera | Audio | Bluetooth | Sensors | Fingerprint |
+-------------------------------------------------------------------------------+
| LINUX KERNEL |
| Display Driver | Wi-Fi Driver | Power Management | Process IPC |
+-------------------------------------------------------------------------------+
2. The Android Activity Lifecycle (Complete State Machine)
An Activity represents a single screen with a user interface. Android manages activities via a stack using 7 lifecycle callback methods:
[Activity Launched]
│
▼
onCreate() ───► (Initialize UI, views & databases)
│
▼
onStart() ───► (Activity becomes visible to user)
│
▼
onResume() ───► (Activity is in FOREGROUND & interactive)
│
[ Activity Running ]
│
(Another activity comes into focus)
│
▼
onPause() ───► (Pause animations, save unsaved state)
│
(Activity no longer visible)
│
▼
onStop() ───► (Release heavy system resources)
│
┌───────────────┴───────────────┐
│ │
(User reopens app) (App killed / finished)
│ │
▼ ▼
onRestart() onDestroy() ──► [Activity Shut Down]
3. Inter-Component Communication: Explicit vs. Implicit Intents
+-------------------+-----------------------------------+---------------------------------------+
| Intent Type | Definition | Code Example |
+-------------------+-----------------------------------+---------------------------------------+
| **Explicit** | Explicitly specifies the exact | `Intent i = new Intent(` |
| | target Activity class to launch. | ` MainActivity.this, |
| | | ` ProfileActivity.class);` |
| | | `startActivity(i);` |
+-------------------+-----------------------------------+---------------------------------------+
| **Implicit** | Declares a general action without | `Intent i = new Intent(` |
| | naming the target app; Android OS | ` Intent.ACTION_VIEW,` |
| | resolves matching apps. | ` Uri.parse("https://sbhuwan.com.np/"));`|
| | | `startActivity(i);` |
+-------------------+-----------------------------------+---------------------------------------+
4. SQLite Database Implementation (SQLiteOpenHelper)
In TU laboratory exams, writing a complete helper class to create tables and execute SQL INSERT, SELECT, and DELETE queries is a standard 10-mark practical question.
package np.com.sbhuwan.bcanotes;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "BcaStudents.db";
private static final int DATABASE_VERSION = 1;
public static final String TABLE_STUDENTS = "students";
public static final String COL_ID = "id";
public static final String COL_NAME = "name";
public static final String COL_SEMESTER = "semester";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_STUDENTS + " ("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COL_NAME + " TEXT NOT NULL, "
+ COL_SEMESTER + " TEXT NOT NULL)";
db.execSQL(createTableQuery);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_STUDENTS);
onCreate(db);
}
// INSERT Operation
public boolean insertStudent(String name, String semester) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COL_NAME, name);
cv.put(COL_SEMESTER, semester);
long result = db.insert(TABLE_STUDENTS, null, cv);
return result != -1; // returns true if inserted successfully
}
// SELECT ALL Operation
public Cursor getAllStudents() {
SQLiteDatabase db = this.getReadableDatabase();
return db.rawQuery("SELECT * FROM " + TABLE_STUDENTS, null);
}
}
Frequently Asked Questions (FAQ)
Q1: What is the AndroidManifest.xml file?
The AndroidManifest.xml is the essential root configuration file of every Android app, declaring package names, activities, permissions (Internet, Camera, Storage), hardware requirements, and services.
Q2: What is the difference between Service and Broadcast Receiver?
A Service is an application component performing long-running operations in the background without a UI (e.g., music playback). A Broadcast Receiver listens and responds to system-wide broadcast announcements (e.g., low battery, incoming SMS).



