0% found this document useful (0 votes)
31 views

Android Journal Theory

Uploaded by

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

Android Journal Theory

Uploaded by

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

TYBBA(CA)

Lab Course: (CA-606)


Computer Laboratory Based on 604
Android Programming
Lab Manual

Name: ______________________________________

Roll No.__________ Academic Year: _______________


Preface:

For the effective execution of Android Programming Laboratory practical, this


lab manual has been prepared. It contains 10 theory questions of
programming and 40 Practical questions.

This lab book will be considered as Journal for final practical exam.

Prepared by:

Mr. Ashish Dhoke


Indira College of Commerce and Science, Pune

Reviewed by:

Under the Guidance of:

Dr. Janardan Pawar


Principal In-Charge
Indira College of Commerce and Science, Pune

Prof. Shivendu Bhushan


Vice-Principal
Indira College of Commerce and Science, Pune
2
Index

Sr. No. Question Assigned Remark


Date
Question1: Create a Simple Application Which
1 Send Hello message from one activity to
another with help of Button (Use Intent).
Question2: Create a Simple Application, which
2 read a positive number from the user and
display its factorial value in another activity.
Question3: Create a Simple Application Which
3
demonstrate Life Cycle of Activity.
Question4: Create an Android Application that
4
Demonstrate DatePicker and TimePicker.
Question5: Create an Android application to
5
demonstrate Progress Bar.
Question6 : Create an Android application that
6 plays an audio(song) start, pause and stop
the audio.
Question7: Create an Android App, it reads the
Students Details (Name, Surname, Class,
7 Gender, Hobbies, Marks) and Display the all
information in another activity in table format on
click of Submit button
Question8: Create an Android Application to find
8 the factorial of a number and Display the
Result on Alert Box.
Question9: Create a Simple Application that
9 performs Arithmetic Operations. (Use 3
TextField, 4 Buttons)
Question10: Create an Android Application that
sends the Notification on click of the button and
10
Display the Notification message on second
activity.
Question11: Create an Android Application to
11 accept two numbers and find power and
Average. Display the result on the next activity
on Button click.

12 Question12: Create an Android application to


demonstrate phone call using Implicit Intent.
Question13: Create Android Application for
performing the following operation on the
table Customer (id, name, address, phno).
13 (use SQLite database)
i) Insert New Customer Details.
ii) Show All the Customer Details on Toast
Message.
Question14: Design Following Screens using
Table Layout. Display the entered text using
Toast.

14

Question15: Create an Android Application that


Demonstrate the rating application using page 1
15 and rating page. Jump from page 1 to rating
page. Select rating and display rating on page 1.
(use Activity Intent for Result).
Question16: Create application to send SMS
16
message to a friend.
Question17: Create an Android Application to
17 perform Zoom In, Zoom Out operation and
display Satellite view, on Google Map.
Question18: Create an Android Application that
18 Demonstrate Radio Button. Change the color of
background as Red, Blue, Green.
Question19: Create an Android Application that
19 Demonstrate ListView and Onclick of List
Display the Toast.
Question20: Write a program to search a specific
20
location on Google Map.

5
Question21: Create an Android App with Login
Screen. On successful login, gives message go
21 to next Activity (Without Using Database& use
Table Layout).

Question22: Create Android application to


perform following operations on table Student
(Sid, Sname ,phno). Use auto increment for Sid
22 and Perform following Operations.
a)Add Student and display its information.
b) Delete Student

Question23: Create following Vertical Scroll View


Creation in Android.

23

Question24: Create an Android Application that


24 Demonstrate Toggle Button.

Question25: Create an Android Application that


will change color of the College Name on click of
25 Push Button and change the font size, font style
of text view using xml.

Question26: Create an Android Application to


26 display satellite view of current location using
Google Map.

27 Question27:Create an Android Application to


Construct image switcher, use 2 buttons
6
Previous and Next to move image on previous
and next image.

Question28 : Write an Android application to


accept two numbers from the user, and displays
28 them, but reject input if both numbers are
greater than 10 and asks for two new numbers.

Question29: Create a Simple calculator.

29

Question30: Create an Android Application that


30
Demonstrate Spinner.
Question31: Create an Android Application to
perform following string operation according to
user selection of radio button.

31

7
Questio32: Create an Android Application that
Demonstrate GridView and Onclick of Item
Display the Toast.

32

Question33: Create an Android Application that


33 Demonstrate AutoCompleteTextView and
MultiAutoCompleteTextView.
Question34: Create an Android Application that
34
Demonstrate Alarm.
Question35: Create an Android Application that
35
Demonstrate Service Life Cycle.
Question36: Create an Android Application that
36
Demonstrate Check Box.
Question37: Create an Android Application that
37
Demonstrate Image Button.
Question38: Create an Android Application that
Demonstrate
ContextMenu

38

8
Question39: Create a Custom ListView in Android
39
Application.
Question40: Create a Simple Android
40 Application to calculate age of a person. (Use
Table Layout)

Theory Questions:
Question 1: Explain Android Adapters.

Android adapters are fundamental components used in Android development


to connect data sources with user interface (UI) elements. They play a critical
role in facilitating the display of data within various UI components such as
ListView, GridView, RecyclerView, Spinner, and others.

There are several types of adapters in Android:

ArrayAdapter: ArrayAdapter is a simple adapter that works well with arrays or


lists of objects. It converts each item in the data source into a view that can
be displayed within an AdapterView. ArrayAdapter is particularly useful when
dealing with simple data structures and when the data can be represented as
a linear list.

BaseAdapter: BaseAdapter is an abstract class that developers can extend to


create custom adapters when the data source does not neatly fit into an array
or list. BaseAdapter provides more flexibility and control over how data is
mapped to views. Developers must implement methods such as getCount(),
getItem(), getItemId(), and getView() to define the behavior of the adapter.

RecyclerView.Adapter: RecyclerView.Adapter is a more advanced and


flexible adapter designed to work with RecyclerView, a powerful UI
component for displaying large datasets with efficient scrolling.
RecyclerView.Adapter offers similar functionalities to BaseAdapter but is
specifically tailored to work seamlessly with RecyclerView. It requires the

9
implementation of methods such as getItemCount(), onCreateViewHolder(),
and onBindViewHolder().

The primary purpose of adapters is to separate the concerns of managing


data and displaying it within the UI. By encapsulating data retrieval and view
creation logic within adapters, developers can achieve better code
organization, reusability, and maintainability. Adapters also contribute to the
performance optimization of Android apps by efficiently handling the display
of large datasets. They achieve this by recycling views, lazily loading data,
and minimizing memory consumption.

Question 2: Write in brief, what is Intent? Explain the types of intents in


android with example.

An Intent in Android is a messaging object that enables communication


between different components of an application or between different
applications. It serves as a bridge for invoking actions, passing data, and
triggering functionalities within the Android system.

Types of Intents in Android:

Explicit Intents: Explicit Intents are used when developers have a specific
target component in mind within their application. They explicitly specify the
component's class name or its package and class name. Explicit Intents are
typically used for intra-application communication.
Example:

10
Intent explicitIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(explicitIntent);

In this example, an explicit Intent is created to navigate from MainActivity to


SecondActivity within the same application.

Implicit Intents: Implicit Intents are utilized when developers want the Android
system to determine the appropriate component to handle a particular action
based on its intent filters. They declare an action to be performed, such as
viewing a webpage or sending an email, without explicitly specifying the
target component. The system then resolves the Intent and launches the
appropriate component from any application that can handle the specified
action.
Example:

Intent implicitIntent = new Intent(Intent.ACTION_VIEW,


Uri.parse("https://www.example.com"));
startActivity(implicitIntent);

In this example, an implicit Intent is created to view a webpage specified by


the URL "https://www.example.com". The Android system resolves this Intent
and opens a web browser (if available) to handle the action of viewing the
webpage.

Question 3: Explain Android Life Cycle.

The Android lifecycle refers to the sequence of states that an Android


component, such as an Activity or Service, goes through during its lifetime.
Understanding the lifecycle is crucial for managing resources, handling user
interactions, and maintaining the state of the application.

For an Activity, the lifecycle states are as follows:

11
Created: The activity is created but not yet visible to the user. This occurs
when the onCreate() method is called. Here, you typically initialize essential
components and set up the UI.

Started: The activity is visible but not yet in the foreground. This state is
reached when the onStart() method is called. Here, you can perform actions
like registering broadcast receivers or preparing data.

Resumed: The activity is in the foreground and has user focus. This is when
the onResume() method is called. It's where you start animations, play
sounds, and handle user interactions.

Paused: Another activity partially obscures the activity, but it's still visible. This
state is reached when the onPause() method is called. Use this state to
release resources not needed when the activity is not visible.

Stopped: The activity is no longer visible to the user. This occurs when the
onStop() method is called. You should release resources here, as the activity
may be destroyed soon.

Destroyed: The activity is being destroyed, either because the user finished it
or the system needs to free resources. The onDestroy() method is called at
this stage, where you should release any resources and unregister any
listeners.

Additionally, there are two transitional states:

Restarted: The activity is restarted after being stopped. This state is reached
when the activity is brought back to the foreground from a stopped state. The
onRestart() method is called before onStart().

SaveInstanceState: The activity is about to be terminated, but its state needs


to be saved so that it can be restored later (for example, when the user
rotates the screen). The onSaveInstanceState() method is called to save the
activity's state, and the saved state bundle is passed as a parameter to both
onCreate() and onRestoreInstanceState().

12
Question 4: How to create AVD’s?

To create Android Virtual Devices (AVDs), you can follow these steps:

Open Android Studio: Launch Android Studio on your computer.

Access AVD Manager: Go to the "Tools" menu and select "AVD Manager."
Alternatively, you can click on the AVD Manager icon in the toolbar.

Create New Virtual Device: In the AVD Manager window, click on the "Create
Virtual Device" button.

Choose Device Definition: Select a device definition from the list. This
represents the device model and hardware specifications of the virtual device
you want to create. Click "Next."

Select System Image: Choose the system image for the Android version you
want to run on the virtual device. If you haven't downloaded the desired system
image, click on the "Download" link next to it. Once downloaded, select the
system image and click "Next."

Configure Virtual Device: Customize the AVD configuration settings such as the
device name, orientation, and more. Adjust the settings according to your
requirements and click "Finish."

Launch Virtual Device: Back in the AVD Manager, select the newly created
virtual device from the list and click on the green "Play" button to launch it.

Use Virtual Device: Once the virtual device is launched, it will emulate an
Android device environment on your computer. You can interact with it just like
a physical Android device, testing your applications or performing debugging
tasks.
Creating AVDs allows you to simulate various Android device configurations,
enabling you to test your applications across different screen sizes, resolutions,
and Android versions without needing physical devices.
13
Question 5: Write in detail about Manifest File.

The Android Manifest file, or AndroidManifest.xml, is a fundamental part of


any Android application. It's an XML file located at the root of your project
directory, acting as the instruction manual for the Android system and other
tools that interact with your app.

Here's a breakdown of what the AndroidManifest.xml reveals about your app:

1. App Structure and Components:

The manifest file declares the building blocks of your application. These
include:

Activities: The different screens users can interact with in your app (e.g., a
main menu, settings screen).
Services: Background processes that run without a direct user interface (e.g., a
music player service).
Broadcast Receivers: Components that respond to system events or
broadcasts sent by other apps (e.g., handling network connectivity changes).
Content Providers: Act as a centralized data repository that other apps can
access (e.g., a content provider for your app's settings).
For each component, the manifest specifies its corresponding Java or Kotlin
class name, allowing the system to identify and launch them.

2. App Metadata:
The manifest file also stores essential app information, including:
Package Name: A unique identifier for your app, like a domain name for
websites.
Version Name and Code: The human-readable version (e.g., 1.0.0) and an
internal version code (e.g., 1).
Application Name: The name displayed to users on the launcher screen.
Icons: Defines the app icons for different device launcher sizes.
Minimum and Target SDK Versions: Specifies the minimum Android API level
your app requires to run and the target version it's optimized for.
14
3. Permissions and Capabilities:
The manifest file is where you declare the permissions your app needs to
access specific features or resources on the device. For instance, accessing
camera functionality requires the CAMERA permission.
Additionally, you can specify hardware and software capabilities your app relies
on, influencing device compatibility.

4. App Entry Point:


The manifest file identifies the main activity of your app, which serves as the
launching point when users open it.

15
:

Question 6 List out a Android SDK features.

One of the key features of the Android SDK is the Android Emulator.
This emulator allows you to test and debug your Android
applications without needing a physical Android device.

The emulator simulates an Android device on your computer,


complete with a virtual screen, operating system, and hardware
components. This provides a convenient and controlled environment
for developing and testing your apps. Here are some of the benefits
of using the Android Emulator:

Cost-effective: It eliminates the need for multiple physical devices


with different Android versions, saving on hardware costs.

Efficient development: You can quickly iterate on your app design


and code, testing changes rapidly within the emulator.

Emulate diverse configurations: The emulator allows you to simulate


various screen sizes, resolutions, and Android API levels, ensuring
your app works properly on a wide range of devices.

Controlled environment: The emulator provides a predictable and


isolated testing ground, free from external factors that might
influence your app's behavior on a physical device.

Question 7 What is Broadcast Receiver?

Signature of Faculty In-charge

16
:

Question 8 Explain any two Event Handlers used in Android.

Two commonly used event handlers in Android are:

Signature of Faculty In-charge

17
:

OnClickListener: The OnClickListener is used to handle click events


on UI elements such as buttons, images, and other interactive views.
It is implemented by attaching an OnClickListener object to the
desired UI element. When the user taps or clicks on the UI element,
the onClick() method of the OnClickListener is invoked, allowing
developers to define the actions to be performed in response to the
click event.

Button myButton = findViewById(R.id.my_button);

myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Action to perform when the button is clicked
Toast.makeText(getApplicationContext(), "Button Clicked",
Toast.LENGTH_SHORT).show();
}
});

OnItemSelectedListener: The OnItemSelectedListener is used to


handle selection events on AdapterView subclasses like Spinner or
ListView. It allows developers to perform actions when an item in the
AdapterView is selected by the user. By implementing the
OnItemSelectedListener interface and attaching it to the
AdapterView, developers can define behavior to be executed when
the user selects an item.
Spinner spinner = findViewById(R.id.spinner);

spinner.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override

Signature of Faculty In-charge

18
:

public void onItemSelected(AdapterView<?> parent, View view, int


position, long id) {
// Action to perform when an item is selected
String selectedItem =
parent.getItemAtPosition(position).toString();
Toast.makeText(getApplicationContext(), "Selected Item: " +
selectedItem, Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// Action to perform when nothing is selected
}
});

Question 9 List Basic Views and explain any three with example.

Basic Views in Android are fundamental UI components that allow


users to interact with the application. Here are some common Basic
Views in Android:

Signature of Faculty In-charge

19
:

TextView: Used to display text on the screen.


EditText: Allows users to input text.
Button: Triggers an action when clicked.
ImageView: Displays images.
CheckBox: Represents a binary choice (checked or unchecked).
RadioButton: Presents a list of options where only one can be
selected.
ToggleButton: Functions like a switch, toggling between two states.
SeekBar: Allows users to select a value within a range by sliding a
thumb.
ProgressBar: Indicates the progress of an operation.
Spinner: Presents a dropdown menu with selectable options.
Now, let's explain three of these Basic Views with examples:

TextView:

Example:
xml
Copy code
<TextView
android:id="@+id/text_view"

Signature of Faculty In-charge

20
:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="18sp"
android:textColor="#000000" />
Explanation: The TextView displays text on the screen. In the
example above, it shows "Hello, World!" with a text size of 18sp and
black text color. TextViews are commonly used to display static text
or dynamically updated content in an Android app.
EditText:

Example:
xml
Copy code
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:inputType="text" />
Explanation: The EditText allows users to input text. In the example
above, it provides a hint "Enter your name" to guide the user.

Signature of Faculty In-charge

21
:

EditTexts are frequently used for capturing user input such as text,
numbers, or passwords in forms or search bars.
Button:

Example:
xml
Copy code
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
Explanation: The Button triggers an action when clicked. In the
example above, it displays the text "Click Me". Buttons are commonly
used to initiate operations or navigate to different screens within the
app. They can be customized with text, icons, and background colors
to suit the app's design.

Signature of Faculty In-charge

22
Question 10: Explain Dialog Box

In Android, dialog boxes follow the same core principles as on other


platforms, but they are specifically designed for the touch-based interface of
mobile devices. Here's a look at Android dialogs:

 Purpose:
o Similar to general dialog boxes, Android dialogs are used for:

 Displaying informative messages, alerts, or confirmations


(e.g., low battery warning).
 Gathering user input through buttons, text fields, or

selection options (e.g., login screen, picking a date).


 Handling errors or exceptions within the app.

 Types of Dialogs:
o Android offers various pre-built dialog classes for common use

cases:
 AlertDialog: The most common type, for displaying

messages, buttons, and optional icons. Used for simple


confirmations, warnings, or error messages.
 DatePickerDialog & TimePickerDialog: Specialized dialogs

for selecting dates and times.


 ProgressDialog (deprecated): Used to show an

indeterminate progress bar while the app performs a long-


running task. It's generally discouraged due to poor user
experience (better to use progress indicators within the app
UI).
 You can also create custom dialogs using layouts and

views for more complex scenarios.


 Functionality:

23
o Android dialogs are modal by default, meaning they block
interaction with the underlying app screen until the user
dismisses them (typically by clicking a button).
o They can be customized with titles, icons, and various button
configurations depending on the dialog type.
 Overall, Android dialogs provide a standardized way to interact with
users, ensuring a consistent experience across different apps. By
using the appropriate dialog type and tailoring it to your specific needs,
you can effectively communicate with users and guide them through
your app's functionalities.

Signature of Faculty In-charge

24

You might also like