i) The Android SDK provides you the API libraries and developer tools necessary to build,
test and debug apps for Android. Answer: b) SDK
ii) An Intent object is a bundle of information which is used by the component that
receives the intent as well as information. Answer: a) Intent
iii) The table layout groups views into rows and columns. Answer: d) Both (a) and (b)
iv) The Gallery is a view that shows items (such as images) in a center-locked, horizontal
scrolling list. Answer: a) Gallery
v) Options menu displays information related to current activity. Answer: b) Options
i) What is meant by Google Map?
Google Map is a web-based service provided by Google that allows users to view maps,
navigate routes, and locate places around the world. In Android development, Google
Maps API is used to embed and interact with maps within an app, allowing features like
current location, directions, markers, and more.
ii) Define Cursor in SQLite:
In SQLite (used in Android for local databases), a Cursor is an interface that provides read
and write access to the result set returned by a database query. It acts like a pointer to the
rows in the result set and allows you to iterate over them.
Example: Cursor cursor = db.rawQuery("SELECT * FROM users", null);
iii) What is Context Menu?
A Context Menu is a floating menu that appears when the user performs a long-press on
an element. It provides actions related to the selected item. Unlike the options menu, it's
specific to the item being interacted with.
iv) Example of TextView: A TextView is used to display text in Android UI.
Example in XML:
<TextView
android:id="@+id/textViewExample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!" />
v) What is AVD?
AVD stands for Android Virtual Device. It is an emulator configuration that allows you to
test Android apps without a physical device. It simulates an Android device on your
computer.
a) Write any five features of Android:
1. Open Source – Android is open-source and freely available.
2. Multi-tasking – It allows multiple apps to run simultaneously.
3. Rich App Framework – Provides tools for building powerful apps.
4. Connectivity – Supports various connectivity options like Wi-Fi, Bluetooth, NFC.
5. Google Integration – Built-in access to Google services like Maps, Gmail, and Play
Store.
b) What is ScrollView? Explain with example:
A ScrollView is a layout that enables vertical scrolling of content if it doesn't fit on the
screen.
Example:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:text="Line 1" />
<TextView android:text="Line 2" />
<!-- Add more views here -->
</LinearLayout>
</ScrollView>
c) With the help of example explain Spinner:
A Spinner is a dropdown menu that lets the user select an item from a list.
Example in XML:
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Java Code: Spinner spinner = findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
d) Explain the term displaying Google Map in detail:
To display Google Maps in Android:
1. Get Google Maps API Key from Google Cloud Console.
2. Add the Maps SDK dependency in build.gradle.
3. Declare permissions and API key in AndroidManifest.xml.
4. Use a MapFragment or SupportMapFragment in layout.
5. Initialize the map in your activity using OnMapReadyCallback.
Example: public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng location = new LatLng(-34, 151);
googleMap.addMarker(new MarkerOptions().position(location).title("Marker"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));
}
e) Explain life cycle of fragment:
A Fragment has its own life cycle, which is closely tied to its host activity.
Fragment Life Cycle States:
1. onAttach() – Fragment is attached to Activity.
2. onCreate() – Initialize essential components.
3. onCreateView() – Inflate fragment layout.
4. onActivityCreated() – Activity and fragment view are created.
5. onStart() – Fragment becomes visible.
6. onResume() – Fragment is active.
7. onPause() – Fragment is paused.
8. onStop() – Fragment is no longer visible.
9. onDestroyView() – View is destroyed.
10. onDestroy() – Cleanup.
11. onDetach() – Fragment is detached from Activity.
f) What is VideoView ? Explain with example:
VideoView is a widget in Android that plays videos from a URL or local resource.
Example:
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Java Code:
VideoView videoView = findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" +
R.raw.sample_video));
videoView.start();
a) What is Toggle Button? How to create it?
A ToggleButton is a UI control that allows the user to change between two states (ON and
OFF). XML Example: <ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="OFF"
android:textOn="ON"/>
Java Code: ToggleButton toggleButton = findViewById(R.id.toggleButton);
toggleButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
Toast.makeText(this, "Toggle is ON", Toast.LENGTH_SHORT).show(); } else {
Toast.makeText(this, "Toggle is OFF", Toast.LENGTH_SHORT).show(); } });
b) Explain life cycle of Activity:
An Android Activity goes through several states:
1. onCreate() – Called when activity is created.
2. onStart() – Activity becomes visible.
3. onResume() – Activity starts interacting with the user.
4. onPause() – Activity is partially visible (another activity overlaps).
5. onStop() – Activity is no longer visible.
6. onRestart() – Called after onStop() before onStart().
7. onDestroy() – Called before activity is destroyed.
Diagram (Simple Overview):
onCreate() → onStart() → onResume()
↓ ↑ ↓
onRestart() onStop() ← onPause()
onDestroy()
c) Simple app to read number & display factorial in another activity
Activity 1 (MainActivity.java): EditText editText = findViewById(R.id.editText);
Button button = findViewById(R.id.button);
button.setOnClickListener(v -> {
int num = Integer.parseInt(editText.getText().toString());
Intent intent = new Intent(MainActivity.this, ResultActivity.class);
intent.putExtra("number", num);
startActivity(intent); });
Activity 2 (ResultActivity.java): int num = getIntent().getIntExtra("number", 1);
int fact = 1;
for(int i = 1; i <= num; i++) {
fact *= i; }
TextView resultView = findViewById(R.id.resultTextView);
resultView.setText("Factorial: " + fact);
d) How to create database in SQLite?
Use SQLiteOpenHelper class to create and manage a database.
Example: public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "StudentDB", null, 1); }
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE students(id INTEGER PRIMARY KEY, name TEXT)"); }
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS students");
onCreate(db); } }
Usage in Activity: DBHelper dbHelper = new DBHelper(this);
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("id", 1); , values.put("name", "John"); , db.insert("students", null, values);
e) How to send message using Intent?
To send an SMS using Intent: Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:1234567890"));
intent.putExtra("sms_body", "Hello! This is a test message.");
startActivity(intent);
Make sure to declare permission in the manifest:
<uses-permission android:name="android.permission.SEND_SMS"/>
f) Explain ListView using Adapter with example
ListView displays a list of scrollable items. It needs an Adapter to bind data.
XML: <ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Java: ListView listView = findViewById(R.id.listView);
String[] items = {"Apple", "Banana", "Mango"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, items); , listView.setAdapter(adapter);
g) Explain any four layouts with example:
1. LinearLayout – Arranges children in a single row or column.
<LinearLayout android:orientation="vertical"> <Button android:text="Button 1"/>
<Button android:text="Button 2"/> </LinearLayout>
2. RelativeLayout – Position elements relative to each other.
<RelativeLayout> <Button android:id="@+id/btn1" android:text="Top"/>
<Button android:layout_below="@id/btn1" android:text="Below"/> </RelativeLayout>
3. ConstraintLayout – Allows flexible positioning with constraints. <ConstraintLayout>
<Button android:id="@+id/button" app:layout_constraintTop_toTopOf="parent" />
</ConstraintLayout> 4 . FrameLayout – Stacks views on top of each other.
<FrameLayout> <ImageView android:src="@drawable/image"/>
<TextView android:text="Overlay text"/> </FrameLayout>
a) Android App: Change color, font size of college name
XML Layout (activity_main.xml):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="20dp">
<TextView
android:id="@+id/collegeName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="K.K. College of Arts, Science"
android:textSize="20sp"
android:textColor="#000000" /> , <Button android:id="@+id/redBtn"
android:text="RED" /> , <Button android:id="@+id/greenBtn" android:text="GREEN" />
<Button android:id="@+id/blueBtn" android:text="BLUE" />
<Button android:id="@+id/yellowBtn" android:text="YELLOW" />
</LinearLayout>
Java Code (MainActivity.java): TextView collegeName = findViewById(R.id.collegeName);
findViewById(R.id.redBtn).setOnClickListener(v -> {
collegeName.setTextColor(Color.RED);
collegeName.setTextSize(25); });
findViewById(R.id.greenBtn).setOnClickListener(v -> {
collegeName.setTextColor(Color.GREEN);
collegeName.setTextSize(30); });
findViewById(R.id.blueBtn).setOnClickListener(v -> {
collegeName.setTextColor(Color.BLUE);
collegeName.setTextSize(22); });
findViewById(R.id.yellowBtn).setOnClickListener(v -> {
collegeName.setTextColor(Color.YELLOW); collegeName.setTextSize(28); });
b) How to do navigation to a specific location:
To navigate to a location using Google Maps:
String uri = "google.navigation:q=K.K.+College+of+Arts,+Science";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
c) Differences:
i) Location Based Services vs Google Maps
Feature Location Based Services Google Maps
Purpose Provides device location Visual map display & navigation
Interface API (LocationManager, Fused) Google Maps SDK/API
Visualization Not displayed to user directly Map with visual feedback
Dependency Core Android API Google Maps service/API key needed
ii) Geocoding vs Reverse Geocoding
Type Converts From Converts To
Geocoding Address Latitude & Longitude
Reverse Geocoding Latitude & Longitude Address
Example: 1. Geocoding: "Mumbai" → (18.96, 72.82) 2. Reverse: (18.96, 72.82) →
"Mumbai, Maharashtra"
d) Architecture of Android:
1. Linux Kernel: Base layer for hardware interaction, memory & process management.
2. Libraries & Android Runtime: 1. C/C++ libraries (SQLite, SSL). 2. ART (Android
Runtime) to run apps.
3. Application Framework: Provides classes for app building (ActivityManager, View,
etc).
4. Applications: User apps like Contacts, SMS, etc.
Diagram:
Applications
Application Framework
Libraries + ART
Linux Kernel
e) Android App for SQLite on Customer Table
DBHelper Class: public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "CustomerDB", null, 1); }
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE customer(id INTEGER, name TEXT, address TEXT, phone
TEXT)"); }
public void insertCustomer(int id, String name, String address, String phone) {
SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("id", id);
cv.put("name", name);
cv.put("address", address);
cv.put("phone", phone);
db.insert("customer", null, cv); }
public String getCustomer() {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM customer", null);
if (cursor.moveToFirst()) {
return "ID: " + cursor.getInt(0) + "\nName: " + cursor.getString(1)
+ "\nAddress: " + cursor.getString(2) + "\nPhone: " + cursor.getString(3); }
return "No data"; } }
Usage in Activity:
DBHelper db = new DBHelper(this);
db.insertCustomer(1, "Raj", "Mumbai", "9999999999");
String details = db.getCustomer();
Toast.makeText(this, details, Toast.LENGTH_LONG).show();
f) Explain the following with examples:
i) ProgressBar Displays ongoing operation.
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"/>
ii) Toast Short popup message.
Toast.makeText(this, "Hello World!", Toast.LENGTH_SHORT).show();
iii) RadioButton
Used for single selection in a group.
<RadioGroup> <RadioButton android:text="Male"/>
<RadioButton android:text="Female"/> </RadioGroup>
iv) CheckBox Used for multiple selections.
<CheckBox android:text="C++"/> <CheckBox android:text="Java"/>
g) Email App with TO, Subject & Message
XML Layout: <EditText android:id="@+id/emailTo" android:hint="To"/>
<EditText android:id="@+id/emailSubject" android:hint="Subject"/>
<EditText android:id="@+id/emailBody" android:hint="Message"/>
<Button android:id="@+id/sendBtn" android:text="Send"/>
Java Code: EditText to = findViewById(R.id.emailTo);
EditText subject = findViewById(R.id.emailSubject);
EditText body = findViewById(R.id.emailBody);
findViewById(R.id.sendBtn).setOnClickListener(v -> {
Intent email = new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto:" + to.getText().toString()));
email.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
email.putExtra(Intent.EXTRA_TEXT, body.getText().toString());
startActivity(Intent.createChooser(email, "Send Email...")); });
a) __________ is a Mobile Operating System based on the Linux Kernel and now
developed by Google. Answer: i) Android
b) A fragment can be used in ___________ activities. Answer: iii) Both i) & ii
c) __________ is a view which groups several items and displays them in a vertical
scrollable list. Answer: ii) List view
d) ___________ class provides the functionality to use the SQLite database.
Answer: i) SQLiteOpenHelper
e) __________ is the process of finding the geographical coordinates of a given address or
location. Answer: ii) Geocoding
a) What is SDK?
SDK stands for Software Development Kit.
It is a collection of tools, libraries, and documentation that developers use to build
applications for a specific platform—in this case, Android.
b) What is Activity?
An Activity is a single screen in an Android app where users can interact with the UI.
It acts as the entry point for user interaction.
c) What is Spinner?
A Spinner is a dropdown menu in Android that allows users to select one item from a list
of options.
d) Define term: Image View.
ImageView is a UI component in Android used to display images from drawable resources,
files, or the internet.
e) How to close database using SQLite?
To close a SQLite database in Android, use:
db.close();
Where db is an instance of SQLiteDatabase.
a) Explain the term displaying Google Map in detail
To display a Google Map in an Android app: 1. Add Google Maps API Key – Get it from
Google Cloud Console.
1. Add Maps SDK dependency in build.gradle:
implementation 'com.google.android.gms:play-services-maps:18.1.0'
3. Add permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
4. Use MapFragment or SupportMapFragment in XML: <fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
5. Initialize map in Java: SupportMapFragment mapFragment =
(SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(googleMap -> {
LatLng college = new LatLng(19.0760, 72.8777); // example coords
googleMap.addMarker(new MarkerOptions().position(college).title("K.K. College"));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(college, 15)); });
b) How to create database in SQLite? Explain with example
Create a database using SQLiteOpenHelper: public class DBHelper extends
SQLiteOpenHelper { public DBHelper(Context context) { super(context,
"StudentDB", null, 1); }
public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE students(id
INTEGER, name TEXT)"); }
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS students"); onCreate(db); } }
Usage: DBHelper dbHelper = new DBHelper(this);
SQLiteDatabase db = dbHelper.getWritableDatabase();
c) Note on List Fragment and Dialog Fragment
ListFragment: A fragment that displays a list of items using ListView. It's useful
for apps with master-detail views.
public class MyListFragment extends ListFragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<>(getActivity(),
android.R.layout.simple_list_item_1, new String[]{"A", "B", "C"})); } }
DialogFragment: Used to show a dialog window within a fragment. More
flexible than AlertDialog.
public class MyDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle("Hello") , .setMessage("This is a dialog.")
.setPositiveButton("OK", null) , .create(); } }
d) Explain different kinds of Layout
1. LinearLayout – Arranges views in vertical or horizontal direction.
2. RelativeLayout – Positions views relative to each other or parent.
3. ConstraintLayout – Flexible layout using constraints; ideal for complex UIs.
4. FrameLayout – Displays one view at a time; overlapping views possible.
5. TableLayout – Arranges elements in rows and columns like a table.
e) Explain Life Cycle of Activity
1. onCreate() – Called when activity is created.
2. onStart() – Activity becomes visible.
3. onResume() – User can interact with activity.
4. onPause() – Partial loss of focus (another activity overlaps).
5. onStop() – Not visible to the user.
6. onRestart() – After stopped, before restart.
7. onDestroy() – Before the activity is destroyed.
f) Explain any four features of Android
1. Open Source – Free and customizable.
2. Multitasking – Run multiple apps at once.
3. Rich UI – XML-based flexible layouts and UI elements.
4. Connectivity – Support for Bluetooth, Wi-Fi, NFC, etc.
5. Google Services Integration – Maps, Gmail, Drive, etc.
a) How to do Navigation to a Specific Location
To navigate using Google Maps in Android:
String uri = "google.navigation:q=K.K.+College+of+Arts,+Science";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
This opens Google Maps and starts turn-by-turn navigation to the specified location.
b) Define the terms: i) SQLite Database A lightweight, open-source database used in
Android to store structured data locally on the device. It supports SQL syntax.
ii) SQLiteOpenHelper A helper class to manage database creation and version
management. It provides methods like:
onCreate() – to create tables.
onUpgrade() – to update schema.
getWritableDatabase() – to write data.
getReadableDatabase() – to read data.
c) What is Menu? Explain Types of Menus
A Menu in Android provides options to the user for app actions.
Types of Menus:
1. Options Menu Appears when the user presses the menu button or three dots.
Example: Settings, About.
2. Context Menu Appears when the user long-presses a view.
Example: Delete, Rename on long press.
3. Popup Menu Anchored to a view (like a button).
Example: Show sorting or filter options.
d) Explain Any Four Types of Buttons
1. Button – Basic clickable button.
Example: Button btn = findViewById(R.id.button);
2. ImageButton – Button with an image instead of text.
Example: <ImageButton android:src="@drawable/icon" />
3. ToggleButton – Two-state button (ON/OFF).
Example: <ToggleButton android:textOn="ON" android:textOff="OFF"/>
4. RadioButton – Used for single-choice selection inside a RadioGroup.
Example: <RadioButton android:text="Male"/>
5. CheckBox (extra) – Used for multiple selections.
Example: <CheckBox android:text="Java"/>
e) Describe Life Cycle of Fragment (with Diagram)
Life Cycle Methods:
1. onAttach() – Fragment is attached to Activity.
2. onCreate() – Initialize fragment.
3. onCreateView() – Create UI view.
4. onActivityCreated() – Activity is fully created.
5. onStart() – Fragment visible.
6. onResume() – Fragment active.
7. onPause() – Fragment not in focus.
8. onStop() – Fragment not visible.
9. onDestroyView() – View is removed.
10. onDestroy() – Fragment is destroyed.
11. onDetach() – Fragment detached from activity.
Diagram:
onAttach() → onCreate() → onCreateView() → onActivityCreated() → onStart() →
onResume()
← onPause() ← onStop() ← onDestroyView() ← onDestroy() ← onDetach()
f) What is VideoView? How to Optimize VideoView?
VideoView
A UI widget used to play video files from internal storage, external storage, or over the
internet.
Code Example: VideoView video = findViewById(R.id.videoView);
video.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" +
R.raw.sample));
video.start();
Optimization Tips:
Use MediaController for playback control.
Use Buffered streaming for online videos.
Avoid high-resolution videos for low-end devices.
Load video in a background thread to avoid UI lag.
g) What is Picker View? Types of Picker View
Picker View allows the user to select a value from a set (date, time, etc.).
Types of Pickers:
1. DatePicker – To select a date (day/month/year).
Example: DatePickerDialog
2. TimePicker – To select time (hour/minute).
Example: TimePickerDialog
3. NumberPicker – To select a number from a range.
Example: DatePickerDialog datePicker = new DatePickerDialog(this,
(view, year, month, day) -> {
}, 2025, 3, 4);
datePicker.show();
a) Explain Architecture of Android
Android architecture has 4 main layers:
1. Linux Kernel (Base Layer) 1. Hardware drivers (camera, audio, Bluetooth).
2. Memory and power management.
2. Libraries and Android Runtime 1. C/C++ libraries: SQLite, WebKit, Media
framework. 2. ART (Android Runtime): Replaces Dalvik, optimized performance,
handles app execution.
3. Application Framework 1. Provides APIs to app developers. 2. Components:
Activity Manager, Notification Manager, Content Providers.
4. Applications Pre-installed (Phone, Contacts, Messages) and user-installed apps.
c) Steps for Linking Activities Using Intents
1. Create Intent object: Intent intent = new Intent(CurrentActivity.this,
TargetActivity.class);
2. Add data (optional): intent.putExtra("key", "value");
3. Start Activity: startActivity(intent);
4. Retrieve data in TargetActivity: Intent i = getIntent();
String value = i.getStringExtra("key");
f) Explain ListView using Adapter (with Example)
ListView shows a scrollable list of items.
Needs an Adapter to bind data to the list.
Layout:
<ListView android:id="@+id/listView" ... />
Java Code:
ListView listView = findViewById(R.id.listView);
String[] data = {"Android", "iOS", "Windows"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, data);
listView.setAdapter(adapter);
b) Write an application for the following Layout
Activity 1 (input layout - activity_main.xml)
<LinearLayout orientation="vertical"> <EditText android:id="@+id/studId" hint="Stud-
id"/> <EditText android:id="@+id/studName" hint="Stud-name"/>
<EditText android:id="@+id/studMark" hint="Stud-Mark"/> <Button
android:id="@+id/okBtn" android:text="OK"/> <Button android:text="Cancel"/>
</LinearLayout>
MainActivity.java public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText id = findViewById(R.id.studId);
EditText name = findViewById(R.id.studName);
EditText mark = findViewById(R.id.studMark);
Button ok = findViewById(R.id.okBtn);
ok.setOnClickListener(v -> { Intent i = new Intent(this, DisplayActivity.class);
i.putExtra("id", id.getText().toString());
i.putExtra("name", name.getText().toString());
i.putExtra("mark", mark.getText().toString());
startActivity(i); }); } }
DisplayActivity.java public class DisplayActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView t = new TextView(this); , Intent i = getIntent();
String data = "ID: " + i.getStringExtra("id") + "\n" +
"Name: " + i.getStringExtra("name") + "\n" +
"Mark: " + i.getStringExtra("mark");
t.setText(data); , setContentView(t); }}
d) Use of onCreate(), onUpgrade(), and getWritableDatabase()
onCreate()
Called when the database is created for the first time.
Used to create tables.
onUpgrade()
Called when the database version is increased.
Used to modify schema without deleting existing data.
getWritableDatabase() Opens the database in write mode.
Example: public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "StudentDB", null, 1); }
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE student(id INTEGER, name TEXT)"); }
public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
db.execSQL("DROP TABLE IF EXISTS student");
onCreate(db); }}
Usage: DBHelper helper = new DBHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
e) Write an application to send Email (Using Intent)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Test Subject");
intent.putExtra(Intent.EXTRA_TEXT, "This is the email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
You can also get values from EditText fields:
EditText to = findViewById(R.id.toField);
String recipient = to.getText().toString();
g) Differentiate Between:
i) Location Based Services vs Google Maps
Feature Location Based Services Google Maps
Uses GPS, WiFi, or cellular to get
Definition Map interface & navigation tool
location
Shows map, routes, search nearby
Function Provides current location
places
API LocationManager or FusedLocation Google Maps SDK
UI No UI (backend) Has full visual map UI
ii) Geocoding vs Reverse Geocoding
Term Description
Geocoding Converts address → latitude/longitude
Reverse Geocoding Converts latitude/longitude → address
Example:
Geocoding: "Mumbai" → (19.0760, 72.8777)
Reverse: (19.0760, 72.8777) → "Mumbai, India"
A) Choose the correct options: [5×1=5]
a) _____ are small activities that can be added or removed from activity.
iii) Fragment
b) ______ show items in a center-locked, horizontal scrolling list.
i) Gallery
c) ______ is a method of SQLite Database
i) rawQuery( )
d) _______ groups view in rows and columns.
iv) Table
e) _______ is the process of finding the geographic coordinates of a given address or
location.
ii) Geocoding
a) Explain use of DatePicker.
DatePicker is a widget that allows the user to select a date (day, month, and year) via a
dialog or calendar interface.
Used for inputting birthdays, appointments, etc.
b) Enlist the types of Menu.
1. Options Menu
2. Context Menu
3. Popup Menu
c) Define AVD.
AVD stands for Android Virtual Device.
It is an emulator configuration that allows you to test Android apps without a physical
device.
d) What is Fragment?
A Fragment is a reusable portion of UI in an activity. It behaves like a mini-activity and can
be added, removed, or replaced during runtime.
e) What is ViewGroup?
A ViewGroup is a layout that contains other views (widgets or other ViewGroups).
Examples: LinearLayout, RelativeLayout, ConstraintLayout.
a) Explain Different Kinds of Layout
1. LinearLayout
o Arranges child views in a single direction (horizontal or vertical).
o Example: Form fields stacked vertically.
2. RelativeLayout
o Views are positioned relative to each other or parent.
o More flexible than LinearLayout.
3. ConstraintLayout
o Advanced layout for designing complex UIs with flat hierarchy.
o Each view is constrained to other views or parent.
4. TableLayout Arranges views in rows and columns like a table.
5. FrameLayout Used to display one view at a time; views stack on top of each
other.
b) Use of onCreate(), onUpgrade(), and getWritableDatabase() methods
These are SQLiteOpenHelper methods used for database management:
onCreate(SQLiteDatabase db)
Called only once when the DB is created. Used to define tables.
db.execSQL("CREATE TABLE student(id INTEGER, name TEXT)");
onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
Called when DB version changes. Used to update schema.
db.execSQL("DROP TABLE IF EXISTS student");
onCreate(db);
getWritableDatabase()
Opens the database for writing operations (insert, update, delete).
c) Write an Application to Send Email using Intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Hello");
intent.putExtra(Intent.EXTRA_TEXT, "This is a test email.");
startActivity(Intent.createChooser(intent, "Send Email"));
d) Methods of SQLiteOpenHelper
Method Description
onCreate() Called when DB is created for first time. Used to define tables.
onUpgrade() Called when DB version is upgraded. Used to update schema.
getWritableDatabase() Returns database in write mode.
getReadableDatabase() Returns database in read mode.
close() Closes the database connection safely.
e) What is Fragment? Explain Types
Fragment is a reusable piece of UI and behavior that can be placed inside an Activity.
Types of Fragments:
1. Static Fragment – Defined in XML and loaded during runtime.
2. Dynamic Fragment – Added/removed programmatically using FragmentManager.
3. ListFragment – Displays a list of items using ListView.
4. DialogFragment – Displays a dialog box inside a fragment.
f) List and Explain Image Views
1. ImageView 1. Displays an image resource (PNG, JPG, etc.) 2. Example:
<ImageView android:src="@drawable/logo" />
2. ImageButton 1. Acts like a button but displays an image. 2. Used for icons or
image-based actions.
3. Gallery (Deprecated) Displays images in a horizontal scrolling list.
4. ImageSwitcher Switches between images with animation.
a) What is Basic Views? Explain any three with example
Basic Views are UI elements in Android used to display content and receive input from
users. 1. TextView Displays text on the screen. <TextView
android:text="Welcome"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
2. EditText Allows user to input text. <EditText
android:hint="Enter your name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
3. Button Triggers an action when clicked. <Button
android:text="Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
b) Explain Life Cycle of Activity
An Android activity goes through several lifecycle stages. Important lifecycle methods are:
1. onCreate() – Called when the activity is first created.
2. onStart() – Activity is becoming visible.
3. onResume() – Activity is now interacting with the user.
4. onPause() – Activity is partially visible (another activity comes in front).
5. onStop() – Activity is no longer visible.
6. onDestroy() – Final call before activity is destroyed.
7. onRestart() – Called after onStop() if activity is coming back.
Diagram:
onCreate() → onStart() → onResume()
↑ ↓ ↓
onRestart() ← onStop() ← onPause()
onDestroy()
c) Explain Features of Android
1. Open Source – Free to use and customize.
2. Multi-tasking – Run multiple apps simultaneously.
3. Rich UI – Supports multimedia, animations, and custom layouts.
4. Connectivity – Supports GSM, Bluetooth, Wi-Fi, NFC.
5. Storage – SQLite for lightweight local database.
6. Google Services – Built-in support for Maps, Gmail, Drive, etc.
d) What is Menu? Explain Types of Menu
A Menu in Android provides options for user actions or settings.
Types of Menus: (1)Options Menu 1. Appears when user presses menu button or 3-
dot icon. 2. Declared in onCreateOptionsMenu(). (2) Context Menu 1. Appears
when user long-presses a view. 2. Created with registerForContextMenu().
(3) Popup Menu 1. Small floating menu anchored to a view. Used for quick
actions.
e) What is Picker View? Explain with Example
A Picker View allows users to select a date, time, or number from a list of options.
Types:
1. DatePicker – For selecting date.
2. TimePicker – For selecting time.
3. NumberPicker – For selecting numbers.
Example (DatePicker):
DatePickerDialog dp = new DatePickerDialog(this,
(view, year, month, day) -> {
String date = day + "/" + (month+1) + "/" + year;
textView.setText(date);
}, 2025, 3, 4);
dp.show();
f) Steps for Linking Activities Using Intents
1. Create Intent Object
Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
2. Attach Data (optional)
intent.putExtra("key", "value");
3. Start Target Activity
startActivity(intent);
4. Receive Data in Target Activity
String value = getIntent().getStringExtra("key");
g) Application for the following layout:
Layout: activity_main.xml <LinearLayout orientation="vertical"> <EditText
android:id="@+id/empName" android:hint="Enter Name" /> <EditText
android:id="@+id/empDate" android:hint="Enter Date" /> <EditText
android:id="@+id/empSalary" android:hint="Enter Salary" /> <Button
android:id="@+id/submit" android:text="Submit" /> <Button android:text="Cancel" />
</LinearLayout>
MainActivity.java public class MainActivity extends AppCompatActivity {
EditText name, date, salary; , protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.empName);
date = findViewById(R.id.empDate);
salary = findViewById(R.id.empSalary);
findViewById(R.id.submit).setOnClickListener(v -> { Intent i = new Intent(this,
DisplayActivity.class);
i.putExtra("name", name.getText().toString());
i.putExtra("date", date.getText().toString());
i.putExtra("salary", salary.getText().toString());
startActivity(i); }) } }
DisplayActivity.java public class DisplayActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView t = new TextView(this);
Intent i = getIntent();
String data = "Name: " + i.getStringExtra("name") +
"\nDate: " + i.getStringExtra("date") +
"\nSalary: " + i.getStringExtra("salary");
t.setText(data); , setContentView(t); }}
a) Differentiate Between
i) Location Based Services (LBS) vs Google Maps
Feature Location Based Services (LBS) Google Maps
Android framework to get device Mapping service to show maps and
Definition
location locations
Uses GPS, Network provider Visual map, routes, navigation
API Used LocationManager Google Maps API
Display
❌ No display ✅ Yes, shows actual map
Map?
Example Weather apps, geofencing Map apps, ride-sharing apps
ii) Geocoding vs Reverse Geocoding
Feature Geocoding Reverse Geocoding
Definition Converts address → coordinates Converts coordinates → address
Input Address (e.g., "Pune, India") Latitude & Longitude
Output Latitude & Longitude Human-readable location
Use Case Location search Show address from map tap
b) Android App to Display Dial Pad using Intent
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:1234567890"));
startActivity(intent);
c) Define:
i) Progress Bar
A visual indicator of progress in a task like downloading or loading.
<ProgressBar android:layout_width="wrap_content"
android:layout_height="wrap_content" />
ii) Toast
A small message popup that disappears after a few seconds.
Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show();
iii) TextView
Displays static or dynamic text.
<TextView android:text="Hello" android:textSize="18sp" />
iv) TableLayout
Displays rows and columns like a table.
<TableLayout>
<TableRow>
<TextView android:text="Name" />
<EditText />
</TableRow>
</TableLayout>
v) LinearLayout
Arranges views vertically or horizontally.
<LinearLayout orientation="vertical">
<Button android:text="OK" />
</LinearLayout>
d) ListView using Adapter – With Example
ListView displays a scrollable list of items using an adapter to bind data.
Steps: 1. Define ListView in XML 2. Create data list (e.g., ArrayList)Use ArrayAdapter to
connect data to ListView
Example: XML (activity_main.xml)
<ListView android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Java (MainActivity.java)
ListView listView = findViewById(R.id.listView);
String[] names = {"John", "Alice", "Bob"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, names);
listView.setAdapter(adapter);
e) Explain Layouts with Example
1. LinearLayout Arranges children in a single line (horizontal/vertical)
<LinearLayout orientation="vertical">
<TextView android:text="Hello" />
</LinearLayout>
2. RelativeLayout Position views relative to each other
<RelativeLayout>
<Button android:id="@+id/b1" android:text="Click" />
<TextView android:layout_below="@id/b1" />
</RelativeLayout>
3. ConstraintLayout Advanced layout for flat, flexible design
<ConstraintLayout>
<Button app:layout_constraintTop_toTopOf="parent" /> </ConstraintLayout>
4. TableLayout Organizes views into rows and columns.
f) Android App to Calculate Factorial
XML <EditText android:id="@+id/input" android:hint="Enter number" />
<Button android:id="@+id/calcBtn" android:text="Calculate" />
<TextView android:id="@+id/result" />
Java EditText input = findViewById(R.id.input);
TextView result = findViewById(R.id.result);
Button calcBtn = findViewById(R.id.calcBtn);
calcBtn.setOnClickListener(v -> { int num = Integer.parseInt(input.getText().toString());
int fact = 1;
for (int i = 1; i <= num; i++) fact *= i;
result.setText("Factorial: " + fact); });
g) How to Create Database in SQLite – Example
Step 1: Create DB Helper Class
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "MyDB", null, 1); }
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE student(id INTEGER, name TEXT)"); }
public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer) {
db.execSQL("DROP TABLE IF EXISTS student");
onCreate(db); } }
Step 2: Use in Activity
DBHelper dbHelper = new DBHelper(this);
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("id", 1);
values.put("name", "John");
db.insert("student", null, values);
A) Choose the correct options:
a) A fragment can be used in ________ activities.
iii) Both i & ii
b) ________ class provides the functionality to use SQLite database.
i) SQLiteOpenHelper
c) The Table Layout groups views into ________.
i) Rows
d) _________ is view which groups several items and displays them in a vertical scrollable
list.
ii) ListView
e) The Android ________ provides you the API libraries and developer tools necessary to
build, test, and debug apps for Android.
ii) SDK
a) Define Image View:
👉 ImageView is a UI component in Android used to display images from resources,
drawable files, or external sources like URLs.
Example:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo" />
b) Explain cursor in SQLite:
👉 A Cursor in SQLite is an interface that provides read and write access to the result set
returned by a database query. It allows you to navigate through rows and access data
column-wise.
Example:
Cursor cursor = db.rawQuery("SELECT * FROM users", null);
c) What is ADT?
ADT stands for Android Development Tools. It was a plugin for Eclipse IDE that provided
tools for building Android apps, like layout editor, project templates, and device
emulators. (Note: Now replaced by Android Studio)
d) Enlist the types of Menu:
The main types of menus in Android are:
Options Menu
Context Menu
Popup Menu
e) Write the purpose of onCreate() method:
The onCreate() method is the entry point of an activity. It is called when the activity is first
created. You use it to set up the UI, bind views, initialize variables, and start processes.
Example:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
a) How to get feedback after sending SMS?
To get feedback after sending an SMS, BroadcastReceiver is used with PendingIntent for
SENT and DELIVERED actions.
Code Snippet:
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new
Intent("SMS_DELIVERED"), 0);
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(context, "SMS sent", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(context, "Sending failed", Toast.LENGTH_SHORT).show();
break; } } }, new IntentFilter("SMS_SENT"));
b) Write an application to perform following operation using menu.
Functionality: 1. Enter string 2. Convert to Uppercase or Lowercase using Menu
MainActivity.java
EditText input;
TextView result;
@Override public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Upper Case");
menu.add("Lower Case");
return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) {
String text = input.getText().toString();
if (item.getTitle().equals("Upper Case")) {
result.setText(text.toUpperCase()); } else {
result.setText(text.toLowerCase()); }
return true; }
Layout: <EditText android:id="@+id/input"/> <TextView android:id="@+id/result"/>
c) Use of onCreate(), onUpgrade(), getWritableDatabase() methods
onCreate(): Called when database is created for the first time. Tables and initial
data are set here.
onUpgrade(): Called when the database version is updated. Used to drop old tables
or migrate data.
getWritableDatabase(): Opens the database in write mode so insert/update/delete
operations can be performed.
Example: @Override public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE users(id INTEGER, name TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS users");
onCreate(db); }
d) Explain Date Picker and Time Picker. List any three methods.
DatePicker: Allows users to select a date.
TimePicker: Allows users to select time (hour/minute).
Common Methods: 1. getYear(), getMonth(), getDayOfMonth() – for DatePicker
2. getHour(), getMinute() – for TimePicker 3. setOnDateSetListener() – to handle selection
event
Example (DatePickerDialog):
DatePickerDialog datePicker = new DatePickerDialog(this,
(view, year, month, day) -> textView.setText(day + "/" + (month+1) + "/" + year),
2024, 3, 4);
datePicker.show();
e) Life Cycle of Fragment
Fragment Life Cycle Methods:
1. onAttach()
2. onCreate()
3. onCreateView()
4. onActivityCreated()
5. onStart()
6. onResume()
7. onPause()
8. onStop()
9. onDestroyView()
10. onDestroy()
11. onDetach()
Diagram (Simple Flow):
onAttach → onCreate → onCreateView → onActivityCreated → onStart → onResume
(on running)
onPause → onStop → onDestroyView → onDestroy → onDetach
(on close)
f) Which methods are overridden while implementing an Option Menu in activity?
1. onCreateOptionsMenu(Menu menu)
→ Used to inflate the menu layout or add items.
2. onOptionsItemSelected(MenuItem item)
→ Used to handle click events for each menu item.
Example:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true; }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.settings) {
return true; }
return super.onOptionsItemSelected(item); }
a) Explain Architecture of Android
The Android architecture is structured in four layers:
1. Linux Kernel
o Acts as an abstraction layer between hardware and software.
o Handles security, memory management, device drivers.
2. Libraries and Android Runtime
o Libraries: SQLite, WebKit, OpenGL, etc.
o Android Runtime includes Dalvik/ART (Android Runtime) and core libraries.
3. Application Framework
o Provides high-level building blocks like Activity Manager, Content Providers,
Resource Manager, etc.
4. Applications
o Top layer where built-in and user-installed apps run (e.g., Contacts, Phone,
SMS, custom apps).
b) Write steps for linking activities using intents
To link one activity to another using explicit intent:
1. Create two activities: MainActivity and SecondActivity
2. Define SecondActivity in AndroidManifest.xml:
<activity android:name=".SecondActivity"></activity>
3. Write intent code in MainActivity:
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
You can also pass data:
intent.putExtra("username", "John");
c) Write an application to display data from Database (any table)
Example: Display from "students" table
DatabaseHelper.java
public Cursor getData() {
SQLiteDatabase db = this.getReadableDatabase();
return db.rawQuery("SELECT * FROM students", null); }
MainActivity.java
Cursor cursor = dbHelper.getData();
if (cursor.moveToFirst()) {
do { String name = cursor.getString(1);
Toast.makeText(this, "Name: " + name, Toast.LENGTH_SHORT).show();
} while (cursor.moveToNext()); }
d) Differentiate between:
i) Location Based Services vs Google Map
Location Based Services Google Maps
Uses GPS/network to get device location Visual mapping and directions
Background services UI with interactive map
No user interface Rich map-based UI
Android LocationManager based Google Maps SDK/API
ii) Geocoding vs Reverse Geocoding
Geocoding Reverse Geocoding
Converts address → coordinates Converts coordinates → address
Example: "New York" → (40.7, -74) Example: (40.7, -74) → "New York"
Uses Geocoder.getFromLocationName() Uses Geocoder.getFromLocation()
e) What is Layout? Explain types of Layout
Layout is a structure that defines the visual structure for a user interface in an Android
activity.
Types of Layouts:
1. LinearLayout – Arranges views vertically or horizontally
2. RelativeLayout – Views are positioned relative to each other
3. ConstraintLayout – Flexible and performance-optimized layout with constraints
4. TableLayout – Arranges views in rows and columns
5. FrameLayout – Stacks views on top of each other
6. GridLayout – Grid-like structure for uniform view distribution
f) Design layout to display result based on percentage
Layout (activity_main.xml): <EditText android:id="@+id/percentage" />
<Button android:onClick="checkResult" android:text="OK"/>
<TextView android:id="@+id/result" />
MainActivity.java: public void checkResult(View view) {
EditText perView = findViewById(R.id.percentage);
TextView resultView = findViewById(R.id.result);
int per = Integer.parseInt(perView.getText().toString());
if (per > 70) resultView.setText("Distinction");
else if (per > 60) resultView.setText("First Class");
else if (per > 40) resultView.setText("Pass Class");
else resultView.setText("Fail"); }
g) Explain the features of Android
1. Open Source – Based on Linux, free and customizable
2. Rich UI – Supports customizable UIs, animations, layouts
3. Connectivity – Supports Bluetooth, WiFi, 5G, NFC
4. Multitasking – Run multiple apps simultaneously
5. Google Services Integration – Maps, Gmail, YouTube, etc.
6. App Distribution – Easily upload apps to Google Play
7. Battery & Resource Management – Optimized for low-power devices
a) Write an application to display Google Map using Intent
To open Google Maps at a specific location using Intent:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:37.7749,-122.4194"));
intent.setPackage("com.google.android.apps.maps");
if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); }
Explanation: 1. geo: URI scheme is used to open Google Maps. 2. The Intent.ACTION_VIEW
triggers the map application. 3. You can also use addresses like geo:0,0?q=K.K. College.
b) Explain the lifecycle of Activity with suitable diagram
Lifecycle Methods of an Activity:
1. onCreate() – Called when activity is first created.
2. onStart() – Activity becomes visible to user.
3. onResume() – Activity is now interacting with the user.
4. onPause() – Activity is partially obscured (e.g., new activity on top).
5. onStop() – Activity is no longer visible.
6. onRestart() – Called when restarting from onStop().
7. onDestroy() – Final call before activity is destroyed.
Diagram:
onCreate()
onStart()
onResume()
↑↓
onPause()
onStop()
onRestart()
onDestroy()
c) Explain specialized Fragments in detail
Specialized Fragments:
1. ListFragment 1. Simplifies displaying a list using ListView. 2. Automatically
handles adapter.
2. DialogFragment 1. Displays a floating dialog box. 2. Replaces the old AlertDialog.
3. PreferenceFragment Manages app settings/preferences using XML.
4. MapFragment Displays Google Map inside a fragment.
Example: DialogFragment
public class MyDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle("Alert")
.setMessage("This is a dialog")
.setPositiveButton("OK", null)
.create(); } }
d) What is VideoView? How to optimize VideoView in ListView
VideoView
A widget that allows video playback in your app.
Supports formats like MP4, 3GP.
Example: VideoView video = findViewById(R.id.videoView);
video.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" +
R.raw.sample));
video.start();
Optimization in ListView:
Don’t autoplay all videos. Play only the visible one.
Use ViewHolder pattern.
Use ExoPlayer for better performance.
Use thumbnail images until clicked.
e) Explain Caveats and Warnings
Caveats: 1. Limitations or potential issues developers should be aware of. 2. Example:
AsyncTask is not suitable for long-running tasks. 3. UI operations must be done on the
main thread.
Warnings: 1. Compiler or Android Studio warnings that suggest poor practices. 2. Example:
“This method is deprecated”, “Missing permissions”.
Why they're important? 1. Prevent runtime crashes. 2. Improve performance and user
experience. 3. Help during debugging and testing.
f) Write an application to send message using Intent
Using SMS Intent:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:1234567890"));
intent.putExtra("sms_body", "Hello, this is a test message!");
startActivity(intent);
Explanation:
sms: URI scheme starts the SMS app.
putExtra adds message text.
This opens the messaging app with number and text pre-filled.
g) Define:
i) ADT (Android Development Tools):
A set of plugins and tools for Eclipse IDE (now obsolete).
Helped in creating, debugging, and packaging Android apps.
ii) AVD (Android Virtual Device):
A device configuration for the Android Emulator.
Simulates a real Android device for testing apps.
iii) Emulator:
A software-based simulation of an Android device.
Allows developers to run and test apps without physical devices.