0% found this document useful (0 votes)
3 views53 pages

MB Programming

The document is a report on mobile programming submitted by Kojens Thapa Magar to Gyaneshwor Dhungana at Tribhuvan University, detailing various labs focused on Android development. It covers the installation of Android Studio, understanding project structure, creating a 'Hello World' application, designing a form with basic views, and emphasizes the use of XML for UI design and Java for app logic. Each lab includes objectives, theory, procedures, source code examples, and conclusions highlighting key learning outcomes and future enhancements.

Uploaded by

bobbyneupane70
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)
3 views53 pages

MB Programming

The document is a report on mobile programming submitted by Kojens Thapa Magar to Gyaneshwor Dhungana at Tribhuvan University, detailing various labs focused on Android development. It covers the installation of Android Studio, understanding project structure, creating a 'Hello World' application, designing a form with basic views, and emphasizes the use of XML for UI design and Java for app logic. Each lab includes objectives, theory, procedures, source code examples, and conclusions highlighting key learning outcomes and future enhancements.

Uploaded by

bobbyneupane70
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/ 53

Tribhuvan University

Prithvi Narayan Campus

Faculty of Humanities and Social Science

Pokhara

A Report on Mobile Programming

Submitted To:
Gyaneshwor Dhungana

BCA Program

Submitted By:

Kojens Thapa Magar

Symbol No: 4802012

BCA (6th Sem)

2025
S.N. TITLE SUBMISSION REMARK
DATE
LAB 1
OBJECTIVE: TO INSTALL AND SET UP ANDROID STUDIO
FOR ANDROID DEVELOPMENT.
TOOLS AND TECHNOLOGIES:
 Android Studio
 Java Development Kit (JDK)
 Android SDK
 Windows/macOS/Linux OS
 Emulator or physical Android device

THEORY:
a) Android Studio
Android Studio is the official IDE for Android development, built on IntelliJ IDEA. It
offers comprehensive tools for building, testing, and debugging Android apps.
b) Java Development Kit (JDK)
The JDK is required to compile and run Java-based Android applications. It provides
essential tools for Java development.
c) Android SDK
The Android SDK includes APIs and developer tools needed to create, test, and debug
Android apps on various Android versions.
d) Emulator
The emulator is a virtual device that mimics real Android hardware, allowing
developers to test apps across different devices and screen sizes without a physical
phone.
PROCEDURE:
a) Download the Android Studio installer from the official Android developer website.
b) Click on the “Download Android Studio” option.

c) Double click on the download “Android Studio-ide.exe” file.

d) “Android Studio Setup” will appear on the screen and click “Next” to proceed.
e) Select the components that we want to install and click on the “Next” button.

f) Now, browse the location where we want to install the Android Studio and
click “Next” to proceed.

g) Choose a start menu folder for the “Android Studio” shortcut and click the “install”
button to proceed.
h) After the successful completion of the installation, click on the “Next” button.

i) Click on the “Finish” button to proceed.

Now, your Android Studio welcome screen will appear on the screen.
j) “Android Studio Setup Wizard” will appear on the screen with the welcome wizard.
Click on the “Next button”.

k) Select (check) the “Standard” option if you are a beginner and do not have any idea
about Android Studio. It will install the most common settings and options for you.
Click “Next” to proceed.

l) Now, select the user interface theme as you want. (I prefer Dark theme (Dracula) that
is most liked by the coders). Then, click on the “Next” button.
m) Now, click on the “Finish” button to download all the SDK components.

And, the downloading and installation process of components gets started.

n) After downloading all the necessary components, click on the “Finish” button.
CONCLUSION:
In this lab, we set up Android Studio, including the JDK, Android SDK, and emulator, gaining a
foundational understanding of the Android development environment. While focused on
installation, it introduced key tools needed to build apps. Performance may vary across devices,
especially those with limited memory. For future steps, exploring SDK and AVD Manager,
adding plugins, customizing the IDE, and building a basic app will reinforce learning. Diving
into Kotlin will also open up modern development possibilities.
LAB 2
OBJECTIVE: TO UNDERSTAND AND EXPLORE THE
ANDROID PROJECT FOLDER STRUCTURE.
THEORY:
Understanding the Structure of an Android Project
a) Overview:
An Android project follows a structured folder hierarchy that separates source code,
resources, and configuration files. This organization helps developers efficiently manage and
navigate the project during development.
b) app/ Directory:
This is the core directory containing everything related to the application. It typically
includes three main subfolders:
 manifests/ – for the app's manifest file
 java/ – for source code and test files
 res/ – for all non-code resources
c) manifests/ Folder:
Contains the AndroidManifest.xml file, which defines essential app details like the package
name, components (activities, services), permissions, and other configuration metadata.
d) java/ Folder:
Holds the app’s source code, written in Java or Kotlin, following the package naming
structure. This folder also includes directories for unit and instrumented tests.
e) res/ Folder:
Stores all non-code resources, organized into subfolders:
 layout/ – XML files defining the UI layout
 drawable/ – Images and drawable assets
 values/ – XML files for strings, styles, colors, etc.
 mipmap/ – Launcher icons optimized for different screen densities
PROCEDURE:
a) Open Android Studio.

b) Create a new project and choose "Empty View Activity."

c) Name the project and configure the language (Java) and SDK version.
d) Once the project is created, explore the Project view in Android Studio.

e) Expand the app folder to view:


 manifests/

 java/

 res/
f) Open each folder and understand the role of the files inside.

g) Examine the build.gradle files under Gradle Scripts.

CONCLUSION:
This lab introduced the structure of an Android project, covering key folders like app, manifests,
java, and res, and explained the role of Gradle in managing dependencies. It focused solely on
structural aspects, excluding app development and advanced topics like multi-module setup or
custom Gradle configurations. For future enhancement, we can build a simple project to observe
structural changes, explore custom Gradle settings, and include Kotlin-based development for
deeper_understanding.
LAB 3
OBJECTIVE: TO CREATE A “HELLO WORLD”
APPLICATION USING ANDROID STUDIO.
THEORY
THEORY:
Understanding the Android Project Structure
Creating an Android app involves more than just a single file—it's a well-organized set of folders
and files that work together. The key components include:
 manifests/ – Contains the AndroidManifest.xml file, which acts as the app’s "identity
card." It defines essential details like the app’s name, components (e.g., activities),
permissions, and more.
 java/ – This is where the core logic resides. It holds Java or Kotlin files that control how
the app functions. This includes the main activity and other supporting classes.
 res/ – Short for resources, this folder contains non-code elements like layouts, strings,
images, and styles that shape the app’s appearance and user experience.
The Role of XML in UI Design
Android uses XML files to design app screens. While drag-and-drop tools exist, XML provides a
more precise and structured way to define UI elements—like buttons, text views, colors, and
layouts. These files are stored in the res/layout/ directory, making the interface design clean and
reusable.
Writing Logic with Java
After designing the UI in XML, Java brings it to life. For example, in a simple "Hello World" app,
the MainActivity.java file handles what appears on the screen and responds to user actions. It also
manages the app's lifecycle—what happens when the app launches, pauses, resumes, or exits.
PROCEDURE:

1. Open Android Studio and start a new project.

2. Select Empty View Activity and click Next.

3. Set the Name as "HelloWorld", choose Java as the programming language, and set
the minimum SDK (e.g., API 21 or higher).

4. Click Finish to create the project.

5. Open activity_main.xml located in res/layout/ and add a TextView to display "Hello


World".

6. Ensure MainActivity.java is set to load activity_main.xml.

7. Connect a device or open an emulator.

8. Click Run to build and launch the app.


SOURCE CODE:

AndroidManifest.xml
1. <?xml version="1.0" encoding="utf-8"?>
2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3. xmlns:tools="http://schemas.android.com/tools">
4.
5. <application
6. android:allowBackup="true"
7. android:dataExtractionRules="@xml/data_extraction_rules"
8. android:fullBackupContent="@xml/backup_rules"
9. android:icon="@mipmap/ic_launcher"
10. android:label="@string/app_name"
11. android:roundIcon="@mipmap/ic_launcher_round"
12. android:supportsRtl="true"
13. android:theme="@style/Theme.Test"
14. tools:targetApi="31">
15. <activity
16. android:name=".MainActivity"
17. android:exported="true">
18. <intent-filter>
19. <action android:name="android.intent.action.MAIN" />
20. <category android:name="android.intent.category.LAUNCHER" />
21. </intent-filter>
22. </activity>
23. </application>
24. </manifest>
Colors.xml
1. <?xml version="1.0" encoding="utf-8"?>
2. <resources>
3. <color name="black">#FF000000</color>
4. <color name="white">#FFFFFFFF</color>
5. </resources>
strings.xml
1. <resources>
2. <string name="app_name">Test</string>
3. </resources>
activity_main.xml
1. <?xml version="1.0" encoding="utf-8"?>
2. <RelativeLayout
3.
4. xmlns:android="http://schemas.android.com/apk/res/android"
5. xmlns:tools="http://schemas.android.com/tools"
6. android:layout_width="match_parent"
7. android:layout_height="match_parent"
8. tools:context=".MainActivity">
9. <TextView
10. android:id="@+id/helloText"
11. android:layout_width="wrap_content"
12. android:layout_height="wrap_content"
13. android:text="Hello Guys!"
14. android:textSize="24sp"
15. android:layout_alignParentTop="true"
16. android:layout_centerHorizontal="true"
17. android:layout_marginTop="20dp" />
18. </RelativeLayout>
MainActivity.java
1. package com.example.test;
2. import android.os.Bundle;
3. import androidx.appcompat.app.AppCompatActivity;
4. public class MainActivity extends AppCompatActivity {
5. @Override
6. protected void onCreate(Bundle savedInstanceState) {
7. super.onCreate(savedInstanceState);
8. setContentView(R.layout.activity_main);
9. }
10. }
OUTPUT:

CONCLUSION:
In this lab, we built a basic "Hello World" app using Android Studio. We explored the project
structure, used XML (activity_main.xml) for UI design, Java (MainActivity.java) for logic, and
reviewed config files like AndroidManifest.xml, colors.xml, and strings.xml. The app was
simple, with no interactivity or advanced features. In the future, we can add user input, lifecycle
handling, fragments, and switch to Kotlin for improved performance and modern development.
LAB 4
OBJECTIVE: TO DESIGN A FORM USING LINEARLAYOUT
WITH BASIC VIEWS SUCH AS TEXTVIEW, EDITTEXT,
BUTTON, RADIOGROUP, ETC.
THEORY:
Android Project Structure: When building an Android app, the project is organized into
several key folders, each with a specific role:
 manifests/ – Contains AndroidManifest.xml, the app’s blueprint. It defines components
like activities and tells Android how the app should run.
 java/ – Holds the Java (or Kotlin) source code, including files like MainActivity.java,
which define the app’s behavior.
 res/layout/ – Stores XML files that describe the user interface for each screen.
 res/values/ – Contains reusable resources like strings, colors, and styles used throughout
the app.

Designing the UI with XML: In Android, UI is designed using XML. It allows you to define the
layout and appearance of elements like text, buttons, and input fields. In this lab, we used
LinearLayout to arrange items in a straight line and added views like TextView, EditText,
Button, and RadioGroup to create a simple interactive layout.

Adding Behavior with Java: After designing the layout, Java is used to make the app
interactive. For example, when a user taps a button or selects an option, Java handles the
response—such as validating input or displaying a message. This brings the static layout to life.
PROCEDURE:

1. Open Android Studio and create a new project.

2. Choose Empty Activity.

3. Configure the project (e.g., Name: FormApp, Language: Java, Minimum SDK:
API 21).

4. Navigate to res/layout/activity_main.xml.

5. Replace the existing layout with a LinearLayout and add the following views:

o TextView for labels.


o EditText for input fields.
o RadioGroup with RadioButton options.
o Button to submit the form.
6. Open MainActivity.java and set up logic if necessary.

7. Run the app on an emulator or physical device.


SOURCE CODE:

activity_main.xml
1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent"
5. android:orientation="vertical"
6. android:padding="16dp">
7.
8. <TextView
9. android:text="Name:"
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content" />
12.
13. <EditText
14. android:id="@+id/editTextName"
15. android:layout_width="match_parent"
16. android:layout_height="wrap_content"
17. android:hint="Enter your name" />
18.
19. <TextView
20. android:text="Email:"
21. android:layout_width="wrap_content"
22. android:layout_height="wrap_content" />
23.
24. <EditText
25. android:id="@+id/editTextEmail"
26. android:layout_width="match_parent"
27. android:layout_height="wrap_content"
28. android:hint="Enter your email"
29. android:inputType="textEmailAddress" />
30.
31. <TextView
32. android:text="Gender:"
33. android:layout_width="wrap_content"
34. android:layout_height="wrap_content" />
35.
36. <RadioGroup
37. android:id="@+id/radioGroupGender"
38. android:layout_width="wrap_content"
39. android:layout_height="wrap_content"
40. android:orientation="horizontal">
41.
42. <RadioButton
43. android:id="@+id/radioMale"
44. android:layout_width="wrap_content"
45. android:layout_height="wrap_content"
46. android:text="Male" />
47.
48. <RadioButton
49. android:id="@+id/radioFemale"
50. android:layout_width="wrap_content"
51. android:layout_height="wrap_content"
52. android:text="Female" />
53. </RadioGroup>
54.
55. <Button
56. android:id="@+id/buttonSubmit"
57. android:layout_width="wrap_content"
58. android:layout_height="wrap_content"
59. android:text="Submit" />
60. </LinearLayout>
OUTPUT:

CONCLUSION:
In this lab, we built a simple form using TextView, EditText, RadioGroup, and Button within a
LinearLayout. It demonstrated how XML defines the UI layout and Java controls the app’s
behavior. We also explored the structure of an Android project, including manifests, java,
res/layout, and res/values. However, the app lacks input validation, user feedback, and data
storage or backend integration.
LAB 5
OBJECTIVE: TO CREATE A SURVEY FORM IN
CONSTRAINT LAYOUT USING VARIOUS WIDGETS SUCH
AS CHECKBOX, RADIOBUTTON, AND SPINNER.
THEORY:
ConstraintLayout in Android
ConstraintLayout is a powerful and flexible layout manager used to design complex user
interfaces in Android without creating deep view hierarchies. It positions and sizes views by
applying constraints relative to other views or the parent layout.
Key Features:
 Positions views relative to siblings or the parent layout
 Uses bias to fine-tune view alignment
 Supports chains to group multiple views in a linear sequence (horizontal or vertical)

Widgets Used in the Survey Form:


 CheckBox – Allows users to select multiple options from a list
 RadioButton (inside a RadioGroup) – Allows only one option to be selected from a
group
 Spinner – Offers a dropdown menu to choose a single item from a predefined list

Java Code for Logic:


Java is used to manage user interactions and process form data. Event listeners like
onClickListener capture user input from the widgets and perform actions such as displaying
results or submitting the information.
PROCEDURE:

a) Open Android Studio and create a new project.

b) Choose Empty Activity.

c) Configure the project with name (e.g., SurveyApp), language (Java), and minimum
SDK.

d) Go to res/layout/activity_main.xml and set the layout to ConstraintLayout.

e) Add the following UI components:

o TextView for instructions or labels.

o EditText to input name or other details.

o RadioGroup with RadioButton options for gender or preferences.

o CheckBox for multiple choice questions.

o Spinner for dropdown selection.

o Button to submit the form.

f) In MainActivity.java, write logic to collect and display or process the selected values.

g) Run the app on an emulator or device to test functionality.


SOURCE CODE: activity_main.xml

1. <?xml version="1.0" encoding="utf-8"?>


2. <androidx.constraintlayout.widget.ConstraintLayout
3. xmlns:android="http://schemas.android.com/apk/res/android"
4. xmlns:app="http://schemas.android.com/apk/res-auto"
5. android:layout_width="match_parent"
6. android:layout_height="match_parent"
7. android:padding="16dp">
8. <TextView
9. android:id="@+id/textViewTitle"
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="Survey Form"
13. android:textSize="24sp"
14. app:layout_constraintTop_toTopOf="parent"
15. app:layout_constraintStart_toStartOf="parent" />
16. <EditText
17. android:id="@+id/editTextName"
18. android:layout_width="0dp"
19. android:layout_height="wrap_content"
20. android:hint="Enter your name"
21. app:layout_constraintTop_toBottomOf="@id/textViewTitle"
22. app:layout_constraintStart_toStartOf="parent"
23. app:layout_constraintEnd_toEndOf="parent" />
24. <RadioGroup
25. android:id="@+id/radioGroupGender"
26. android:layout_width="wrap_content"
27. android:layout_height="wrap_content"
28. android:orientation="horizontal"
29. app:layout_constraintTop_toBottomOf="@id/editTextName"
30. app:layout_constraintStart_toStartOf="parent">
31. <RadioButton
32. android:id="@+id/radioMale"
33. android:layout_width="wrap_content"
34. android:layout_height="wrap_content"
35. android:text="Male" />
36. <RadioButton
37. android:id="@+id/radioFemale"
38. android:layout_width="wrap_content"
39. android:layout_height="wrap_content"
40. android:text="Female" />
41. </RadioGroup>
42. <CheckBox
43. android:id="@+id/checkBoxReading"
44. android:layout_width="wrap_content"
45. android:layout_height="wrap_content"
46. android:text="Reading"
47. app:layout_constraintTop_toBottomOf="@id/radioGroupGender"
48. app:layout_constraintStart_toStartOf="parent" />
49. <CheckBox
50. android:id="@+id/checkBoxTraveling"
51. android:layout_width="wrap_content"
52. android:layout_height="wrap_content"
53. android:text="Traveling"
54. app:layout_constraintTop_toBottomOf="@id/checkBoxReading"
55. app:layout_constraintStart_toStartOf="parent" />
56. <Spinner
57. android:id="@+id/spinnerCountry"
58. android:layout_width="wrap_content"
59. android:layout_height="wrap_content"
60. app:layout_constraintTop_toBottomOf="@id/checkBoxTraveling"
61. app:layout_constraintStart_toStartOf="parent" />
62. <Button android:id="@+id/buttonSubmit"
63. android:layout_width="wrap_content"
64. android:layout_height="wrap_content"
65. android:text="Submit"
66. app:layout_constraintTop_toBottomOf="@id/spinnerCountry"
67. app:layout_constraintStart_toStartOf="parent" />
68. </androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
1. package com.example.test;
2. import android.os.Bundle;
3. import android.view.View;
4. import android.widget.*;
5. import androidx.appcompat.app.AppCompatActivity;
6. public class MainActivity extends AppCompatActivity {
7. EditText editTextName;
8. RadioGroup radioGroupGender;
9. CheckBox checkBoxReading, checkBoxTraveling;
10. Spinner spinnerCountry;
11. Button buttonSubmit;
12. @Override
13. protected void onCreate(Bundle savedInstanceState) {
14. super.onCreate(savedInstanceState);
15. setContentView(R.layout.activity_main);
16. // Initializing views
17. editTextName = findViewById(R.id.editTextName);
18. radioGroupGender = findViewById(R.id.radioGroupGender);
19. checkBoxReading = findViewById(R.id.checkBoxReading);
20. checkBoxTraveling = findViewById(R.id.checkBoxTraveling);
21. spinnerCountry = findViewById(R.id.spinnerCountry);
22. buttonSubmit = findViewById(R.id.buttonSubmit);
23. // Setting data in spinner
24. String[] countries = {"Nepal", "UAE", "USA", "UK"};
25. ArrayAdapter<String> adapter = new
ArrayAdapter<>(this,
android.R.layout.simple_spinner_dropdown_item, countries);
26. spinnerCountry.setAdapter(adapter);
27. // Button click listener
28. buttonSubmit.setOnClickListener(new View.OnClickListener() {
29. @Override
30. public void onClick(View v) {
31. String name = editTextName.getText().toString();
32. int selectedGenderId = radioGroupGender.getCheckedRadioButtonId();
33. RadioButton selectedGender = findViewById(selectedGenderId);
34. String gender = selectedGender != null ? selectedGender.getText().toString() : "Not selected";
35. String hobbies = "";
36. if (checkBoxReading.isChecked()) hobbies += "Reading ";
37. if (checkBoxTraveling.isChecked()) hobbies += "Traveling ";
38. String country = spinnerCountry.getSelectedItem().toString();
39. Toast.makeText(MainActivity.this,
40. "Name: " + name + "\nGender: " + gender + "\nHobbies: " + hobbies + "\nCountry: " +
country,
41. Toast.LENGTH_LONG).show();
42. }
43. });
44. } }
OUTPUT:

CONCLUSION:
This lab involved creating a survey form using ConstraintLayout with CheckBox, RadioButton,
and Spinner widgets. We learned to build flexible layouts, handle user input, and show Toast
messages in Java.
Limitations included no input validation, no data storage, and limited options in form elements.
Future improvements could add input validation, data storage, dynamic form fields, and
enhanced GUI design with better styling and interactivity.
LAB 6
OBJECTIVE: TO CREATE A BASIC ANDROID
APPLICATION THAT DEMONSTRATES THE USE OF
STRING RESOURCES AND COLOR RESOURCES IN
THE USER INTERFACE.
THEORY:
1. Android Project Structure: An Android project consists of:
 A Java/Kotlin folder containing the app’s logic.
 A res/ folder holding UI layouts, drawables, strings, and colors.
 An AndroidManifest.xml file for app configuration.
2. Role of XML in UI Creation: XML defines the layout and views (e.g., TextView, Button),
separating the UI design from app logic. This separation improves maintainability.
3. String Resources: String values are stored in res/values/strings.xml for reuse and easy
localization.
Example: <string name="welcome_message">Welcome to My App</string>
4. Color Resources: Colors are defined in res/values/colors.xml to ensure UI consistency and
simplify_theming.
Example: <color name="custom_blue">#2196F3</color>
5. Java Code for Logic: Java binds the XML UI components using findViewById() and
implements the app logic. In this example, the app displays a string and applies a color resource.
PROCEDURE:

a) Open Android Studio and create a new project.

b) Choose "Empty View Activity" template.

c) Set project name (e.g., ResourceDemoApp), choose Java as language, and minimum
SDK.

d) Design UI in activity_main.xml using TextView.

e) Define custom strings in res/values/strings.xml.

f) Define custom colors in res/values/colors.xml.

g) Apply string and color resources to the TextView.

h) Build and run the app on an emulator or real device.


SOURCE CODE:

activity_main.xml
1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout
3. xmlns:android="http://schemas.android.com/apk/res/android"
4. android:layout_width="match_parent"
5. android:layout_height="match_parent"
6. android:orientation="vertical"
7. android:background="@color/white"
8. <TextView
9. android:id="@+id/tvWelcome"
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="@string/welcome_message"
13. android:layout_gravity="center"
14. android:textColor="@color/custom_blue"
15. android:textSize="24sp" />
16. </LinearLayout>

strings.xml
1. <resources>
2. <string name="app_name">ResourceDemoApp</string>
3. <string name="welcome_message">Welcome !!!</string>
4. </resources>

colors.xml
<resources>
<color name="white">#FFFFFF</color>
<color name="custom_blue">#2196F3</color>
</resources>
MainActivity.java
1. package com.example.test;
2. import android.os.Bundle;
3. import androidx.appcompat.app.AppCompatActivity;
4. public class MainActivity extends AppCompatActivity {
5. @Override
6. protected void onCreate(Bundle savedInstanceState) {
7. super.onCreate(savedInstanceState);
8. setContentView(R.layout.activity_main);
9. }
10. }

OUTPUT:

CONCLUSION:
In this lab, we built a simple Android app using string and color resources for better maintenance
and localization. We designed the UI with XML and implemented logic in Java, connecting
components via findViewById(). The app showed static text without interactivity.
Future improvements could include multi-language support and dynamic theme switching based
on user or system preferences.
LAB 7
OBJECTIVE: TO ADD A CUSTOM APPLICATION ICON IN
AN EXISTING ANDROID PROJECT.
THEORY:

1. Project Structure in Android:

An Android project is organized into several folders. Application launcher icons are stored in
the **res/mipmap** directory under various subfolders (like mipmap-hdpi, mipmap-xhdpi,
etc.) to support different screen densities. The app icon is linked using the
**AndroidManifest.xml** file.

2. Launcher Icons:

Launcher icons are the icons displayed on the home screen or app drawer. To ensure
compatibility with different devices, icons are included in multiple resolutions based on
screen density (hdpi, xhdpi, xxhdpi, etc.).

3. Image Asset Studio:

Android Studio provides Image Asset Studio to easily create and manage launcher icons. It
automatically generates all required icon sizes for different densities and updates the
necessary references in the manifest.
PROCEDURE:

a) Open an existing Android project in Android Studio.

b) Right-click on the res folder → New → Image Asset.

c) In the Asset Type dropdown, select Image.

d) Upload your custom image/logo (PNG, JPG, or SVG recommended).

e) Configure icon properties (trim, resize, shape, background).

f) Confirm the icon name (typically ic_launcher).

g) Click Next and then Finish to generate the icon.

h) Android Studio will automatically add the icons in all mipmap- folders.

i) Open AndroidManifest.xml and verify the app icon is set like

this: android:icon="@mipmap/ic_launcher"

j) Run the app on a device or emulator to see the custom icon.


SOURCE CODE:
AndroidManifest.xml:
1. <application
2. android:icon="@mipmap/ic_launcher"
3. android:label="@string/ app_name"
4. android:roundIcon="@mipmap/ic_launcher _foreground"
5. android:theme="@style/Theme.App">
6. ...
7. </application>
The generated icon files will be placed in:

OUTPUT:

CONCLUSION:
In this lab, I learned to create a custom app icon using Image Asset Studio in Android Studio. I
explored launcher icons, their placement in res/mipmap, and how Android handles screen
densities. The custom icon was applied via AndroidManifest.xml.
Limitation: Only static icons were used; adaptive or animated icons were not explored.
Future Improvement: Implement adaptive icons, dark mode support, and vector-based icons
for better scalability and modern UI support.
LAB 8
OBJECTIVE: TO CREATE AN ANDROID APPLICATION
THAT DEMONSTRATES PASSING DATA BETWEEN TWO
ACTIVITIES USING INTENT.
THEORY:

1. Overview of the Android Project Structure:


An Android project includes XML files for the user interface, Java/Kotlin files for logic, and
the AndroidManifest.xml file for application configuration. Activities manage each of the
app's screens and are specified in the manifest.

2. XML's Role in UI Design:


EditText, Button, and TextView are examples of user interface elements that are arranged
and designed using XML.

3. Activity and Intent Navigation:


To request another element for an action, use intents, which are message objects. There are
two kinds of them:

Explicit Intent (to initiate a particular activity)


Implicit Intent (invoking other applications' components)
In this lab, data is passed from one activity to another using the putExtra() method with explicit
intent.

4. Java Code for Logic:

Java is used to manage user interactions and define the behavior of the app. Event handling
(like button clicks) is done using event listeners such as onClickListener, which also handle
the transfer of data between activities.
PROCEDURE:

a) Open Android Studio and create a new project.

b) Choose “Empty Activity”.

c) Name the project (e.g., IntentDemoApp) and select Java as the language.

d) Create two activities: MainActivity and SecondActivity.

e) Design the layout in activity_main.xml with an EditText and a Button.

f) Design the layout in activity_second.xml with a TextView to display received data.

g) In MainActivity.java, collect text from EditText and send it to SecondActivity using


an intent.

h) In SecondActivity.java, receive the data and display it in TextView.

i) Declare SecondActivity in AndroidManifest.xml.

j) Run the app on an emulator or device and test the data passing.
SOURCE CODE:

activity_main.xml
1. <LinearLayout
2. xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent"
5. android:orientation="vertical"
6. android:padding="16dp">
7.
8. <EditText
9. android:id="@+id/editTextMessage"
10. android:layout_width="match_parent"
11. android:layout_height="wrap_content"
12. android:hint="Enter your message" />
13.
14. <Button
15. android:id="@+id/buttonSend"
16. android:layout_width="wrap_content"
17. android:layout_height="wrap_content"
18. android:text="Send"
19. android:layout_marginTop="20dp"/>
20.
21. <TextView
22. android:layout_width="wrap_content"
23. android:layout_height="wrap_content"
24. android:text="Activity First"
25. android:layout_gravity="center"
26. android:layout_marginTop="100dp"
27. android:textSize="40dp"
28. android:fontFamily="sans-serif-medium"
29. android:textColor="@color/red"/>
30.
31. </LinearLayout>
MainActivity.java
1. package com.example.test;
2.
3. import android.content.Intent;
4. import android.os.Bundle;
5. import android.widget.Button;
6. import android.widget.EditText;
7. import androidx.appcompat.app.AppCompatActivity;
8.
9. public class MainActivity extends AppCompatActivity {
10. EditText editTextMessage;
11. Button buttonSend;
12.
13. @Override
14. protected void onCreate(Bundle savedInstanceState) {
15. super.onCreate(savedInstanceState);
16. setContentView(R.layout.activity_main);
17.
18. editTextMessage = findViewById(R.id.editTextMessage);
19. buttonSend = findViewById(R.id.buttonSend);
20.
21. buttonSend.setOnClickListener(v -> {
22. String message = editTextMessage.getText().toString();
23. Intent intent = new Intent(MainActivity.this,
24. SecondActivity.class); intent.putExtra("message_key", message);
25. startActivity(intent);
26. });
27. }
28. }
activity_second.xml
1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2. android:layout_width="match_parent"
3. android:layout_height="match_parent"
4. android:orientation="vertical"
5. android:padding="16dp">
6. <TextView
7. android:id="@+id/textViewResult"
8. android:layout_width="match_parent"
9. android:layout_height="wrap_content"
10. android:textSize="20sp"/>
11. <TextView
12. android:layout_width="wrap_content"
13. android:layout_height="wrap_content"
14. android:text="Activity Second"
15. android:layout_gravity="center"
16. android:layout_marginTop="100dp"
17. android:textSize="40dp"
18. android:textColor="@color/red"/> </LinearLayout>
SecondActivity.java
1. package com.example.test;
2. import android.os.Bundle;
3. import android.widget.TextView;
4. import androidx.appcompat.app.AppCompatActivity;
5. public class SecondActivity extends AppCompatActivity {
6. TextView textViewResult;
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. super.onCreate(savedInstanceState);
10. setContentView(R.layout.activity_second);
11. textViewResult = findViewById(R.id.textViewResult);
12. String receivedMessage = getIntent().getStringExtra("message_key");
13. textViewResult.setText(receivedMessage);
14. } }
OUTPUT:

CONCLUSION:
In this lab, I learned to use explicit intents to pass data between two activities in an Android app
using putExtra() and getStringExtra(). This helped us understand intent-based navigation and
basic interactivity. The Limitation of The app only supports passing simple strings; it doesn’t
handle complex data or return results. The Future Improvement is to Use
startActivityForResult() or ActivityResultLauncher for two-way communication and pass objects
via Bundle or Parcelable.
LAB 9
OBJECTIVE: TO DEMONSTRATE THE USE OF
STARTACTIVITYFORRESULT() TO GET DATA BACK
FROM A SECOND ACTIVITY.
THOERY:

1. Overview of the Android Project Structure:


An Android project contains Java/Kotlin files for logic and XML files for UI design.
AndroidManifest.xml specifies activities, while Java manages the logic for screen-to-screen
communication.

2. UI Design with XML:


UI elements like EditText, Button, and TextView are defined using XML. These are used to
gather information and show it to the user.

3. Activity and initiation:


ActivityForResult() startsActivityForResult() is used when one activity starts another and
waits for a response.

StartActivityForResult() is used in the first activity.

SetResult() is used in the second activity to pass back data.

OnActivityResult() is overridden in the first activity to handle the returned result.

4. Logic Code in Java:


Java is used to manage event listeners (e.g., button clicks), handle data passing between
activities, and process the returned results from the second activity.
PROCEDURE:

a) Open Android Studio and create a new project.

b) Choose “Empty Activity”.

c) Name the project (e.g., ResultIntentDemoApp) and select Java.

d) Create two activities: MainActivity and SecondActivity.

e) Design the layout of activity_main.xml with a Button and TextView.

f) Design activity_second.xml with an EditText and Button.

g) In MainActivity.java, use startActivityForResult() to start SecondActivity.

h) In SecondActivity.java, get input from EditText and send it back using setResult().

i) Handle the result in onActivityResult() in MainActivity and display it in TextView.

j) Declare both activities in the AndroidManifest.xml.

k) Run and test the app on an emulator or device.


SOURCE CODE:

activity_main.xml
1. <LinearLayout
2. xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent"
5. android:padding="16dp"
6. android:orientation="vertical">
7.
8. <Button
9. android:id="@+id/buttonOpen"
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="Open Second Activity" />
13.
14. <TextView
15. android:id="@+id/textViewResult"
16. android:layout_width="wrap_content"
17. android:layout_height="wrap_content"
18. android:layout_marginTop="24dp"
19. android:textSize="18sp"
20. android:text="Result will appear here" />
21. </LinearLayout>
MainActivity.java
1. package com.example.test;
2. import android.app.Activity;
3. import android.content.Intent;
4. import android.os.Bundle;
5. import android.widget.Button;
6. import android.widget.TextView;
7. import androidx.appcompat.app.AppCompatActivity;
8.
9. public class MainActivity extends AppCompatActivity {
10. private static final int REQUEST_CODE = 1;
11. TextView textViewResult;
12. Button buttonOpen;
13. @Override
14. protected void onCreate(Bundle savedInstanceState) {
15. super.onCreate(savedInstanceState);
16. setContentView(R.layout.activity_main);
17. textViewResult = findViewById(R.id.textViewResult);
18. buttonOpen =
findViewById(R.id.buttonOpen); 19.
20. buttonOpen.setOnClickListener(v -> {
21. Intent intent = new Intent(MainActivity.this, SecondActivity.class);
22. startActivityForResult(intent, REQUEST_CODE);
23. });
24. }
25. @Override
26. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
27. super.onActivityResult(requestCode, resultCode, data);
28. if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
29. String result = data.getStringExtra("returnedData");
30. textViewResult.setText(result);
31. }
32. }
33. }
activity_second.xml
1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2. android:layout_width="match_parent"
3. android:layout_height="match_parent"
4. android:padding="16dp"
5. android:orientation="vertical">
6. <EditText
7. android:id="@+id/editTextInput"
8. android:layout_width="match_parent"
9. android:layout_height="wrap_content"
10. android:hint="Enter data to return" />
11. <Button
12. android:id="@+id/buttonReturn"
13. android:layout_width="wrap_content"
14. android:layout_height="wrap_content"
15. android:layout_marginTop="20dp"
16. android:text="Return Data" />
17. </LinearLayout>
SecondActivity.java
1. package com.example.test;
2. import android.app.Activity;
3. import android.content.Intent;
4. import android.os.Bundle;
5. import android.widget.Button;
6. import android.widget.EditText;
7. import androidx.appcompat.app.AppCompatActivity;
8. public class SecondActivity extends AppCompatActivity {
9. EditText editTextInput;
10. Button buttonReturn;
11. @Override
12. protected void onCreate(Bundle savedInstanceState) {
13. super.onCreate(savedInstanceState);
14. setContentView(R.layout.activity_second);
15.
16. editTextInput = findViewById(R.id.editTextInput);
17. buttonReturn = findViewById(R.id.buttonReturn);
18.
19. buttonReturn.setOnClickListener(v -> {
20. String message =
21. editTextInput.getText().toString(); Intent
22. resultIntent = new Intent();
23. resultIntent.putExtra("returnedData", message);
24. setResult(Activity.RESULT_OK, resultIntent);
25. finish();
26. }
27. }

OUTPUT:

CONCLUSION:

In this lab, I learned how to use startActivityForResult() to pass data between two activities
in an Android application. We successfully created an interface where data entered in the
second activity was returned and displayed in the first activity. One limitation is that
startActivityForResult() is now deprecated in newer Android versions. In future improvements,
we can replace it with the modern ActivityResultLauncher API for better compatibility and
cleaner code.
LAB 10
OBJECTIVE: TO DEMONSTRATE THE ANDROID ACTIVITY
LIFECYCLE USING LOGCAT IN ANDROID STUDIO.
THEORY:

An overview of the structure of the Android project:


The AndroidManifest.xml file, which declares activities and configurations, XML files for
UI design, and Java/Kotlin files for logic are commonly included in Android projects. A
single screen with a user interface is represented by an activity.

Function of XML in UI Design:


An Android application's layout is specified using XML. TextViews, buttons, and other
widgets are organized using layouts like LinearLayout and ConstraintLayout.

Java Logic Code:


Java code implements an activity's logic and manages user interactions. Key lifecycle
methods such as onCreate(), onStart(), onResume(), onPause(), onStop(), onRestart(), and
onDestroy() are overridden in the activity class for lifecycle demonstration.

Lifecycle of an Activity:
From creation to destruction, an Android activity goes through multiple stages. Lifecycle
callback is used to manage these phases.
PROCEDURE:

a) Open Android Studio and create a new project.

b) Choose Empty View Activity.

c) Name the project (e.g., ActivityLifecycleDemo) and select Java as the language.

d) Modify activity_main.xml to include a simple UI (e.g., a TextView for reference).

e) In MainActivity.java, override all activity lifecycle methods:

o onCreate()

o onStart()

o onResume()

o onPause()

o onStop()

o onRestart()

o onDestroy()

f) Inside each method, use Log.d() to print a message indicating the method execution.

g) Run the app on an emulator or device.

h) Use Logcat to observe the printed lifecycle messages as the activity state changes
(e.g., when the app is minimized or closed).
SOURCE CODE:

activity_main.xml
1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent"
5. android:orientation="vertical"
6. android:gravity="center"
7. android:padding="16dp">
8.
9. <TextView
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="Activity Lifecycle Demo"
13. android:textSize="20sp"
14. android:textStyle="bold" />
15. </LinearLayout>

MainActivity.java
1. package com.example.activitylifecycledemo;
2. import android.os.Bundle;
3. import android.util.Log;
4. import androidx.appcompat.app.AppCompatActivity;
5. public class MainActivity extends AppCompatActivity {
6. private static final String TAG = "Lifecycle";
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. super.onCreate(savedInstanceState);
10. setContentView(R.layout.activity_main);
11. Log.d(TAG, "onCreate called");
12. }
13. @Override
14. protected void onStart() {
15. super.onStart();
16. Log.d(TAG, "onStart called");
17. }
18.
19. @Override
20. protected void onResume() {
21. super.onResume();
22. Log.d(TAG, "onResume called");
23. }
24.
25. @Override
26. protected void onPause() {
27. super.onPause();
28. Log.d(TAG, "onPause called");
29. }
30.
31. @Override
32. protected void onStop() {
33. super.onStop();
34. Log.d(TAG, "onStop called");
35. }
36.
37. @Override
38. protected void onRestart() {
39. super.onRestart();
40. Log.d(TAG, "onRestart called");
41. }
42.
43. @Override
44. protected void onDestroy() {
45. super.onDestroy();
46. Log.d(TAG, "onDestroy called");
47. }
48. }
OUTPUT:

CONCLUSION:

In this lab, I investigated the full lifecycle of an Android activity and learned how different
methods are activated at different app states. We were able to see the order of lifecycle
method calls as the activity begins, continues, pauses, and ends by using Logcat. The fact that
this project only logs one activity is one of its limitations; future research can examine multi-
activity transitions. Adding user interaction buttons to more interactively trigger various
lifecycle behaviors would be one potential improvement.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy