1.
AIM
To develop a simple Android application with a Login Module using Java in Android Studio that accepts a
username and password, validates the credentials, and displays an appropriate message to the user.
2. OBJECTIVE
• Understand the basics of Android application development using Java.
• Learn to design a user interface using XML layout files.
• Implement event handling using Button's OnClickListener.
• Use EditText, TextView, and Button widgets in an Android layout.
• Display output using a Toast message and a TextView.
• Run and test the application on the Android Emulator.
3. SOFTWARE REQUIREMENTS
Component Details
Operating System Windows 10/11 / macOS / Ubuntu Linux
IDE Android Studio (Latest Stable Version)
Programming Language Java (JDK 8 or above)
Android SDK API Level 21 (Android 5.0 Lollipop) or higher
Emulator / Device Android Virtual Device (AVD) or Physical Android Device
Gradle Gradle Build Tool (included with Android Studio)
4. THEORY
Android is an open-source mobile operating system developed by Google, based on the Linux kernel.
Android applications are primarily written in Java or Kotlin. Each Android app is built using components
such as Activities, Fragments, Services, and Broadcast Receivers.
Activity is the fundamental building block of any Android application. It represents a single screen with a
user interface. Every Activity has a corresponding XML layout file that defines the visual components
(widgets) on the screen.
Important UI Widgets used in this experiment:
• EditText — An input field that allows the user to enter text. Used here for Username and Password
fields.
• Button — A clickable widget. Here it triggers the login validation logic.
• TextView — A widget that displays text to the user. Used to show "Login Successful" message.
• Toast — A small pop-up message that appears briefly on screen. Used here to display "Login Fail"
when credentials are incorrect.
Login Logic: The application compares the entered username and password with predefined correct
values (admin / 1234). If they match, the TextView shows "Login Successful". Otherwise, a Toast message
"Login Fail" is displayed.
5. PROCEDURE
Step 1 — Open Android Studio
SFGC, Yelahanka | Mobile Application Development Lab | Asst. Prof. CHIRAG D Page 1
Launch Android Studio. Click on "New Project".
Step 2 — Select Project Template
Choose "Empty Activity" from the template list. Click Next.
Step 3 — Configure the Project
Set Name: LoginApp | Package: [Link] | Language: Java | Minimum SDK: API 21.
Click Finish.
Step 4 — Design the Layout (activity_main.xml)
Open res > layout > activity_main.xml. Switch to Code view and replace the content with the XML
code provided below.
Step 5 — Write the Java Logic ([Link])
Open java > [Link] > [Link]. Replace its content with the Java code
provided below.
Step 6 — Verify [Link]
Open app > manifests > [Link]. Ensure it matches the provided manifest code (no
changes are usually needed).
Step 7 — Run the Application
Click the green Run button (Shift+F10). Select the AVD emulator and click OK. Wait for the app to
launch on the emulator.
Step 8 — Test the Application
Enter admin as username and 1234 as password → click Login. Observe "Login Successful" in the
TextView. Then try wrong credentials and observe the Toast message.
6. PROGRAM CODE
File 1: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp"
android:gravity="center">
<!-- App Title -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Page"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="24dp" />
<!-- Username Input -->
SFGC, Yelahanka | Mobile Application Development Lab | Asst. Prof. CHIRAG D Page 2
<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:inputType="text"
android:layout_marginBottom="12dp" />
<!-- Password Input -->
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"
android:layout_marginBottom="20dp" />
<!-- Login Button -->
<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginBottom="20dp" />
<!-- Result TextView -->
<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:textColor="#2E6DA4"
android:textStyle="bold" />
</LinearLayout>
File 2: [Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
SFGC, Yelahanka | Mobile Application Development Lab | Asst. Prof. CHIRAG D Page 3
import [Link];
public class MainActivity extends AppCompatActivity {
// Declare UI components
EditText etUsername, etPassword;
Button btnLogin;
TextView tvResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Link variables to XML widgets
etUsername = findViewById([Link]);
etPassword = findViewById([Link]);
btnLogin = findViewById([Link]);
tvResult = findViewById([Link]);
// Set click listener on Login button
[Link](new [Link]() {
@Override
public void onClick(View v) {
// Read user input
String username = [Link]().toString();
String password = [Link]().toString();
// Validate credentials
if ([Link]("admin") && [Link]("1234")) {
// Correct credentials
[Link]("Login Successful");
} else {
// Wrong credentials — show Toast
[Link]([Link],
"Login Fail",
Toast.LENGTH_SHORT).show();
[Link]("");
});
File 3: [Link]
<?xml version="1.0" encoding="utf-8"?>
SFGC, Yelahanka | Mobile Application Development Lab | Asst. Prof. CHIRAG D Page 4
<manifest xmlns:android="[Link]
package="[Link]">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]">
<!-- Main Activity declaration -->
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
7. OUTPUT
Scenario Action Result
Username: admin
Click Login TextView shows: "Login Successful"
Password: 1234
Username: user Toast message: "Login Fail"
Click Login
Password: pass TextField remains empty
Username: (empty)
Click Login Toast message: "Login Fail"
Password: (empty)
Expected Screen: On launching the app, the user sees a title "Login Page", two input fields (Username,
Password), and a Login button. After entering correct credentials and tapping Login, the text "Login
Successful" appears below the button in blue. For incorrect credentials, a brief Toast notification pops up
at the bottom of the screen displaying "Login Fail".
8. RESULT
The Android application with a Login Module was successfully developed and executed in Android Studio
using Java. The application correctly validates the entered username and password. When valid
credentials are provided (admin / 1234), the TextView displays "Login Successful". When incorrect
credentials are entered, a Toast message displaying "Login Fail" is shown on the screen. The experiment
was completed successfully.
SFGC, Yelahanka | Mobile Application Development Lab | Asst. Prof. CHIRAG D Page 5
9. VIVA QUESTIONS WITH ANSWERS
Q1. What is Android? Name its key components.
Ans: Android is an open-source, Linux-based mobile operating system developed by Google. Its key
components are: Activity (a single screen), Service (background process), Broadcast Receiver
(system-wide event listener), and Content Provider (data sharing between apps).
Q2. What is an Activity in Android?
Ans: An Activity represents a single screen with a user interface. It is the entry point for user interaction.
Every Android app must declare at least one Activity in the [Link] file.
Q3. What is the difference between Toast and TextView?
Ans: Toast is a short-lived pop-up message that appears on screen for a few seconds and disappears
automatically — it cannot be interacted with. TextView is a permanent UI widget in the layout that
displays text until it is explicitly changed or cleared by the programmer.
Q4. What is the purpose of [Link]?
Ans: [Link] is the configuration file of every Android application. It declares all the
components of the app (Activities, Services, etc.), the required permissions, the minimum SDK version,
the app icon, label, and the launcher activity.
Q5. What is the role of [Link] in Android?
Ans: [Link] is an auto-generated file maintained by the Android build system. It maps every resource
(layout files, strings, drawables, IDs) to a unique integer constant, allowing Java code to reference XML
resources using syntax like [Link] or [Link].activity_main.
Q6. What does setContentView() do?
Ans: setContentView([Link].activity_main) inflates the specified XML layout file and sets it as the
content view of the current Activity. It must be called inside onCreate() before accessing any UI widgets.
Q7. What is the difference between match_parent and wrap_content?
Ans: match_parent makes a widget expand to fill the entire available space of its parent container.
wrap_content makes a widget shrink to only occupy as much space as needed to display its content.
SFGC, Yelahanka | Mobile Application Development Lab | Asst. Prof. CHIRAG D Page 6