0% found this document useful (0 votes)
14 views25 pages

MAD Day

Uploaded by

tirthbabariya454
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)
14 views25 pages

MAD Day

Uploaded by

tirthbabariya454
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/ 25

Q.1 Full Answer: Differentiate between JVM and DVM.

Explain DVM in
detail.

Difference between JVM and DVM

Point JVM (Java Virtual Machine) DVM (Dalvik Virtual Machine)


Purpose Runs Java applications Runs Android applications
File Type Executes .class (Java bytecode) Executes .dex (Dalvik Executable)
Architect Stack-based machine Register-based machine (fewer instructions,
ure faster)
Optimiza General purpose, not optimized for Designed for mobile → less memory, better
tion mobile battery usage
Platform Platform-independent for desktop & Specially designed for Android OS
servers

Explanation of DVM (Dalvik Virtual Machine)

• Definition: DVM is a special virtual machine for Android that runs apps written in
Java but converted into .dex files.
• Dex Compiler: Java .class files are combined into a single .dex file using the dx
tool, which DVM executes.
• Register-based: Unlike JVM (stack-based), DVM is register-based, so it needs fewer
instructions → faster for mobiles.
• Memory Efficient: Uses less RAM and optimizes battery, important for
smartphones.
• Multi-Tasking: Can run multiple apps at the same time, each in its own process.
• Garbage Collection: Frees unused memory automatically.
Q.2: Explain Android architecture with proper diagram OR Enlist and
define the components of android application.

Android Architecture

Android architecture has 4 main layers (bottom to top):

1. Linux Kernel
a. Base of Android.
b. Manages hardware (camera, display, WiFi, Bluetooth, etc.).
c. Handles memory & process management.
2. Libraries & Android Runtime (ART)
a. Libraries: Provide features like graphics, media, and database (SQLite).
b. Android Runtime: Earlier DVM, now ART, executes Android apps.
3. Application Framework
a. Provides classes and services for app development.
b. Examples: Activity Manager (controls activity lifecycle), Content Providers
(share data), Resource Manager (handles UI resources).
4. Applications
a. Top layer.
b. System apps (Phone, Contacts, SMS) and User apps (WhatsApp, Instagram,
etc.).

Diagram (for exam):

(Draw a pyramid with 4 layers – Applications → Application Framework → Libraries +


Runtime → Linux Kernel)

Components of Android Application

Every Android app has 4 main components:

1. Activity – A single screen with UI (e.g., Login screen).


2. Service – Runs in background (e.g., Music player).
3. Broadcast Receiver – Responds to system messages (e.g., Battery low alert).
4. Content Provider – Shares data between apps (e.g., Contacts app).

Q.3: What is AndroidManifest.xml? Write its usages with example.

AndroidManifest.xml

• Definition:
The AndroidManifest.xml file is the blueprint of every Android app.
It gives the Android system essential info about the app before it runs.

Usages of AndroidManifest.xml

1. App Info → Defines app name, icon, theme.


2. Declare Components → Registers activities, services, broadcast receivers,
content providers.
3. Permissions → Specifies what the app can access (e.g., Internet, Camera,
Contacts).
4. API Levels → Declares minimum and target Android versions.
5. Intent Filters → Defines which activity should open first (launcher) and how app
interacts with other apps.
6. Hardware Features → States required features like GPS, Bluetooth, etc.

Example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

<!-- Permission to access Internet -->


<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Explanation of Example:

• <application> → Defines app info.


• <activity> → Declares main screen (MainActivity).
• <intent-filter> → Marks it as launcher activity.
• <uses-permission> → App can use Internet.

Q.4: What is Fragment? Differentiate between Activity and Fragment.

Fragment

• A Fragment is a small reusable part of UI inside an Activity.


• It can have its own layout, logic, and lifecycle but always works within an Activity.
• Useful for multi-pane UIs (like in tablets: list on left, details on right).

Difference between Activity and Fragment

Point Activity Fragment


Definition A single screen with UI in an A part of UI inside an Activity
app
Lifecycle Has its own lifecycle Lifecycle is dependent on Activity
Independen Works alone (entry point of Cannot exist alone, must be in an
ce app) Activity
Reusability Not reusable directly Reusable in multiple Activities
Example LoginActivity, MainActivity LoginFormFragment, MenuFragment

Q.5: What is an Activity? Explain the Activity Lifecycle with all events in
detail.

Activity in Android

• An Activity is a single screen with a user interface in an Android app.


• Example: Login screen, Home screen, Settings screen.
• Every Android app has at least one Activity (usually MainActivity).

Activity Lifecycle (with Callbacks)

The Android system manages Activity states using lifecycle methods:

1. onCreate() → Called when Activity is created. Initialize UI and variables.


2. onStart() → Activity becomes visible to user.
3. onResume() → Activity is in the foreground and user can interact.
4. onPause() → Activity is partially hidden (another Activity is on top). Pause ongoing
tasks.
5. onStop() → Activity is not visible (in background). Release resources.
6. onRestart() → Called when Activity is coming back from stopped state.
7. onDestroy() → Activity is being destroyed. Final cleanup happens.
Lifecycle Diagram (for exam):

(Draw a flow with arrows showing onCreate → onStart → onResume → onPause → onStop →
onRestart → onDestroy)

Marks Split (6M):

• Definition + Example of Activity → 1-2 Marks


• Lifecycle explanation (all 7 methods) → 4 Marks
• (Optional: Diagram for neatness)

Q.6: Write a code to send data from one activity to another activity using
implicit intent.

Answer (6M)

Definition:

• An Intent is used to move from one Activity to another.


• Implicit Intent lets the system decide which app/component will handle the
request.

Code Example – Send Data using Implicit Intent

SenderActivity.java

public class SenderActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sender);
}

public void sendMessage(View view) {


Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello from
SenderActivity!");
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Send Message"));
}
}

activity_sender.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Message"
android:onClick="sendMessage"/>
</LinearLayout>

ReceiverActivity.java (to get data if another Activity of same app handles it)

public class ReceiverActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receiver);

Intent intent = getIntent();


String message = intent.getStringExtra(Intent.EXTRA_TEXT);
TextView textView = findViewById(R.id.textView);
textView.setText(message);
}
}

activity_receiver.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"/>
</LinearLayout>

Q.7: Write a code to send SMS from Android App using the concept of
explicit intent.
Answer (6M)

Definition:

• Explicit Intent = We specify exactly which component/activity should handle the


task.
• For sending SMS → we use Intent.ACTION_VIEW with "sms:" URI.

Code Example – Send SMS with Explicit Intent

SmsActivity.java

public class SmsActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
}

public void sendSms(View view) {


String phoneNumber = "1234567890"; // Receiver’s number
String message = "Hello, this is a test SMS!";

Intent intent = new Intent(Intent.ACTION_VIEW);


intent.setData(Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
startActivity(intent); // Opens SMS app with filled details
}
}

activity_sms.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/sms_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS"
android:onClick="sendSms"/>
</LinearLayout>

Q.8: What is AVD? Explain the process of creating AVD in Android


application development.

What is AVD?

• AVD (Android Virtual Device) is an emulator configuration that simulates a real


Android device on your computer.
• It allows developers to test apps on different screen sizes, Android versions, and
hardware features without using a physical device.

Components of AVD:

1. Device Type → Phone, Tablet, TV, etc.


2. System Image → Android version to run (e.g., Android 11).
3. Hardware Profile → RAM, Storage, Camera, Sensors.
4. Other Settings → Orientation, resolution, network, etc.

Steps to Create AVD in Android Studio

1. Open AVD Manager


a. In Android Studio → Go to Tools > AVD Manager.
2. Create New Virtual Device
a. Click on Create Virtual Device.
3. Select Hardware
a. Choose a device (e.g., Pixel 4, Nexus 5X).
4. Choose System Image
a. Select Android version (download if needed).
5. Configure AVD
a. Set name, orientation (portrait/landscape), RAM, storage, etc.
6. Finish & Launch
a. Save configuration → Click Play button to start emulator.

Q.9: Draw and explain the lifecycle of a Fragment.

Fragment Lifecycle

A Fragment is a part of UI inside an Activity and has its own lifecycle, but it is always
controlled by the Activity.

Lifecycle Methods of Fragment

1. onAttach(Context) → Fragment is attached to Activity.


2. onCreate(Bundle) → Fragment created, initialize resources.
3. onCreateView(LayoutInflater, ViewGroup, Bundle) → Create UI (inflate XML).
4. onActivityCreated(Bundle) → Activity and Fragment UI are ready.
5. onStart() → Fragment becomes visible.
6. onResume() → Fragment is active and user can interact.
7. onPause() → User leaves fragment partially (another activity/fragment comes on
top).
8. onStop() → Fragment is no longer visible.
9. onDestroyView() → Fragment’s UI is removed from screen.
10. onDestroy() → Fragment instance is destroyed.
11. onDetach() → Fragment is fully detached from Activity.
Diagram (for exam):

onAttach → onCreate → onCreateView → onActivityCreated



onStart → onResume

onPause → onStop

onDestroyView → onDestroy → onDetach

Q.10: Explain Versions in Android.

Android Versions

Android has gone through many versions, each bringing new features and improvements.
Here are the important versions (short & exam-friendly):

1. Android 1.0 (2008) → First release, basic apps & Android Market.
2. Eclair (2.0, 2009) → Multiple accounts, HTML5 support, improved Maps.
3. Ice Cream Sandwich (4.0, 2011) → Unified phone + tablet UI, Holo design.
4. Lollipop (5.0, 2014) → Material Design, better notifications, battery saver.
5. Marshmallow (6.0, 2015) → App permissions, Doze mode (battery save).
6. Nougat (7.0, 2016) → Split-screen multitasking, better notifications.
7. Oreo (8.0, 2017) → Picture-in-Picture, notification dots.
8. Pie (9.0, 2018) → Gesture navigation, adaptive battery.
9. Android 10 (2019) → System-wide Dark Mode, better privacy.
10. Android 11 (2020) → Chat bubbles, improved media & privacy.
11. Android 12 (2021) → Material You design (custom colors).
12. Android 13 (2022) → Better personalization & security.

Features of Android OS (general points)

• Open Source (Linux-based).


• User-friendly UI.
• Multitasking support.
• Rich notification system.
• Multiple connectivity options (WiFi, Bluetooth, NFC).
• Secure with regular updates.

Q.11: Explain type of Intent with suitable example.

Intent in Android

• Intent = A messaging object used to communicate between components (Activity,


Service, BroadcastReceiver).
• It can start another activity, call a service, or deliver a broadcast.

Types of Intent

1. Explicit Intent

• Used when you know the exact component (Activity/Service) to start.


• Example: Going from MainActivity to SecondActivity.

Code Example:

Intent intent = new Intent(MainActivity.this, SecondActivity.class);


startActivity(intent);

2. Implicit Intent

• Used when you don’t specify the component; Android decides the best
app/component.
• Example: Open a webpage in a browser.

Code Example:

Intent intent = new Intent(Intent.ACTION_VIEW);


intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);
Q.12: What is Toast? Explain how to customize it? Write code to display
toast message on button click.

Toast in Android

• A Toast is a small popup message shown on the screen for a short time.
• It gives quick feedback to the user (e.g., “Message Sent”, “Button Clicked”).
• It disappears automatically and does not block user interaction.

Customizing a Toast

• By default → only text + duration.


• We can customize → background, text color, size, add images/icons.
• Done by creating a custom layout XML and inflating it.

Code Example – Simple Toast on Button Click

MainActivity.java

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button button = findViewById(R.id.button);


button.setOnClickListener(v ->
Toast.makeText(MainActivity.this, "Button Clicked!",
Toast.LENGTH_SHORT).show()
);
}
}

activity_main.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"/>
</LinearLayout>

Q.13: Explain UI Components of Android application.

UI Components in Android

Android provides many User Interface (UI) components to design app screens. Here are
the main ones (with examples):

1. TextView

• Displays text to the user (labels, messages, headings).


• Example:

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

2. EditText

• Input field where the user can enter text (name, email, password).
• Example:

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name" />

3. Button

• A clickable component to perform an action (Submit, Login).


• Example:

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />

4. ImageView

• Displays an image or icon.


• Example:

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
5. ListView

• Shows a scrollable list of items.


• Example: Contacts list, Messages list.

6. Spinner (Dropdown)

• Provides a drop-down menu for selecting one option.

Q.14: Enlist and define types of Menus in Android.

Menus in Android

Menus provide a way for users to interact with app features easily. Android supports
different types of menus.

Types of Menus

1. Options Menu
a. Main menu of the app.
b. Appears in the Action Bar or when pressing the menu button.
c. Used for global actions like Settings, Search, Help.
d. Example:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
2. Context Menu
a. Appears when user long-presses an item.
b. Shows actions specific to that item (like Delete, Edit, Share).
c. Example: Long press on text → Copy/Paste menu.

3. Popup Menu
a. Small floating menu anchored to a specific view (button, icon).
b. Displays a quick list of actions.
c. Example: 3-dot menu next to a message → Reply, Forward, Delete.

4. Submenu
a. A menu inside another menu.
b. Used to group related options.
c. Example: Settings → Display → {Brightness, Font Size, Theme}.

Q.15: Explain the concept of RecyclerView. Write down the steps to


implement RecyclerView in Android application.

RecyclerView in Android

• RecyclerView is an advanced and efficient version of ListView.


• Used to display a large set of items in a scrollable list or grid.
• It reuses (recycles) views that go off-screen → improves performance.
• Supports animations and custom layouts.

Steps to Implement RecyclerView

1. Add Dependency
a. In build.gradle:
implementation 'androidx.recyclerview:recyclerview:1.2.1'

2. Add RecyclerView to Layout

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

3. Create Item Layout (e.g., item_layout.xml)

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"/>

4. Create Model Class (e.g., Item.java)

public class Item {


String name;
public Item(String name) { this.name = name; }
public String getName() { return name; }
}

5. Create Adapter Class (binds data to views)

public class MyAdapter extends


RecyclerView.Adapter<MyAdapter.ViewHolder> {
List<Item> itemList;

public static class ViewHolder extends RecyclerView.ViewHolder {


TextView textView;
public ViewHolder(View view) {
super(view);
textView = view.findViewById(R.id.textView);
}
}
public MyAdapter(List<Item> items) { itemList = items; }

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int
viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_layout, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.textView.setText(itemList.get(position).getName());
}

@Override
public int getItemCount() { return itemList.size(); }
}

6. Set Adapter in Activity

RecyclerView recyclerView = findViewById(R.id.recyclerView);


recyclerView.setLayoutManager(new LinearLayoutManager(this));

List<Item> list = new ArrayList<>();


for(int i=1; i<=20; i++) list.add(new Item("Item " + i));

MyAdapter adapter = new MyAdapter(list);


recyclerView.setAdapter(adapter);

Q.16: List various layouts available in Android. Explain any two out of
that.
Layouts in Android

Layouts are containers that arrange UI components (Views) on the screen.

Types of Layouts

1. LinearLayout – Arranges views in a single row/column.


2. RelativeLayout – Places views relative to each other or parent.
3. ConstraintLayout – Advanced layout, flexible positioning using constraints.
4. FrameLayout – Designed to hold one child; multiple children overlap.
5. GridLayout – Places views in rows & columns (grid format).
6. TableLayout – Organizes views into rows and columns (like a table).

Explanation of Any Two Layouts

1. LinearLayout

• Arranges child views horizontally or vertically.


• Simple for stacking UI components.

Example:

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"/>
</LinearLayout>

2. RelativeLayout

• Places child views relative to each other (e.g., toLeftOf, below, centerInParent).
• Useful for complex UIs.

Example:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:layout_below="@id/textView"/>
</RelativeLayout>

Q.17: What is ScrollView, CardView and ListView? Explain any one with
suitable example.

1. ScrollView

• A layout that lets the user scroll content vertically (or horizontally).
• Used when content is larger than the screen size.

Example:

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a scrollable content"/>

<!-- Add many TextViews/Buttons here -->

</LinearLayout>
</ScrollView>

2. CardView

• A container with rounded corners & shadow (card-like look).


• Used to display structured data (e.g., product cards, profile cards).

Example:

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a CardView"/>
</androidx.cardview.widget.CardView>

3. ListView

• A view that displays items in a scrollable list.


• Requires an Adapter to bind data.

Example (Java + XML):

XML:

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Java:

String[] items = {"Item 1", "Item 2", "Item 3"};


ListView listView = findViewById(R.id.listView);

ArrayAdapter<String> adapter = new ArrayAdapter<>(


this, android.R.layout.simple_list_item_1, items);
listView.setAdapter(adapter);

Q.18: Explain View and ViewGroup in Android.

View in Android

• A View is the basic UI building block in Android.


• It represents a single component like Button, TextView, ImageView, EditText.
• Responsible for drawing on the screen and handling user interaction (clicks,
input).

Examples of View:

• TextView → displays text.


• Button → clickable element.
• ImageView → shows image.

ViewGroup in Android

• A ViewGroup is a container that holds multiple Views (and even other


ViewGroups).
• Defines how its child views are arranged on the screen.
• It is the base class for all layouts.

Examples of ViewGroup (Layouts):

• LinearLayout → arranges views in row/column.


• RelativeLayout → arranges views relative to each other.
• ConstraintLayout → flexible UI with constraints.
• ScrollView → holds one child view that can scroll.

Key Difference

Feature View ViewGroup


Definition Single UI element Container of Views
Examples Button, TextView, ImageView LinearLayout,
RelativeLayout
Purpose Display content & handle Arrange child views on
interaction screen

You might also like