Mobile Application Development (22617) Practical No.
27
Practical No. 27: Create sample application with login module. (Check username and
password) On successful login, Change Text View “Login Successful” and on login
fail, alert user using Toast “Login fail”.
I. Practical Significance
This day Login and Registration form in Android are part of every application. So, when we are
programming, we work with many registration forms. Forms can be very different from a
simple login or registration to a complex ordering form for any application.
II. Relevant Program Outcomes (POs)
PO1- Basic knowledge
PO2- Discipline knowledge
PO3- Experiments and practice
PO7- Ethics
III. Competency and Practical Skills
“Create simple Android applications.”
1. This practical is expected to develop the following skills
2. Able to design the GUI framework for any application.
3. Able to develop simple login form.
IV. Relevant Course Outcome(s)
1. Configure Android environment and development tools.
2. Develop rich user Interfaces by using layouts and controls.
3. Use User Interface components for android application
development.
V. Practical Outcome (PrOs)
Create sample application with login module. (Check username and password) On successful
login, Change Text View “Login Successful” and on login fail, alert user using Toast “Login fail”.
VI. Relevant Affective Domain Related Outcome(s)
1. Work collaboratively in team
2. Follow ethical Practices.
VII. Minimum Theoretical Background
A login application is the screen asking your credentials to login to some particular application.
You might have seen it when logging into Facebook, twitter etc.
First you have to define two Text View asking username and password of the user. Define a
button with login text.
In the java file, inside the method of onClick get the username and passwords text using
getText() and toString() method and match it with the text using equals() function.
The last thing you need to do is to provide a security mechanism, so that unwanted attempts
should be avoided. For this initialize a variable and on each false attempt, decrement it. And
when it reaches to 0, disable the login button.
Maharashtra State Board of Technical Education 1
Mobile Application Development (22617) Practical No. 27
VIII. Resources required(Additional)
Sr. Instrument /Object Specification Quantity Remarks
No.
Android enabled 2 GB RAM 1 Data cable is
smartphone / Android mandatory for
1
version supporting emulators
emulator
IX. Practical related Questions
Note: Below given are few sample questions for reference. Teachers must design more
such questions to ensure the achievement of identified CO.
1. Explain the use of equals() function.
2. List the important functions which are related to GUI component “Button”.
3. State the uses of Toast message.
(Space for answers)
Answers:
1. equals() method is used to compare two strings and returns true or false.
2. Button is subclass of TextView which is subclass of View. You can use any inherited method
from these classes. e.g.
CharSequence getText()
Return the text that TextView is displaying.
final void setText(CharSequence text)
Sets the text to be displayed.
void setTextColor(int color)
Sets the text color for all the states (normal, selected, focused) to be this color.
… and many more.
3. In android, Toast is a small popup notification which is used to display an information about
the operation which we performed in our app. The Toast will show the message for a small
period of time and it will disappear automatically after a timeout.
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to create the login form and display login successful/ Unsuccessful toast
message.
(Space for answers)
Answers:
Maharashtra State Board of Technical Education 2
Mobile Application Development (22617) Practical No. 27
//MainActivity.java
package com.jamiapolytechnic.experiment271;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import static android.widget.Toast.*;
public class MainActivity extends AppCompatActivity {
EditText txtUserName, txtPassword;
Button btnLogin, btnCancel;
String userName = "mad";
String password = "22617";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtUserName = findViewById(R.id.txtUserName);
txtPassword = findViewById(R.id.txtPassword);
btnLogin = findViewById(R.id.btnLogin);
btnCancel = findViewById(R.id.btnCancel);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtUserName.getText().toString().equals(userName) &&
txtPassword.getText().toString().equals(password)) {
Toast.makeText(getApplicationContext(),"Login successful",
LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),"Login denied", LENGTH_LONG).show();
Maharashtra State Board of Technical Education 3
Mobile Application Development (22617) Practical No. 27
}
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtUserName.setText("");
txtPassword.setText("");
}
});
}
}
//=====================================================================
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.19" />
Maharashtra State Board of Technical Education 4
Mobile Application Development (22617) Practical No. 27
<EditText
android:id="@+id/txtUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvUserName" />
<TextView
android:id="@+id/tvPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtUserName" />
<EditText
android:id="@+id/txtPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvPassword" />
Maharashtra State Board of Technical Education 5
Mobile Application Development (22617) Practical No. 27
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtPassword" />
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnLogin" />
</androidx.constraintlayout.widget.ConstraintLayout>
Maharashtra State Board of Technical Education 6
Mobile Application Development (22617) Practical No. 27
XI. References / Suggestions for further Reading
1. https://www.tutorialspoint.com/android
2. https://stuff.mit.edu
3. https://www.tutorialspoint.com/android/android_advanced_tutorial.pdf
4. https://developer.android.com
XII. Assessment Scheme
Performance indicators Weightage
Process related (10 Marks) 30%
1. Logic Formation 10%
2. Debugging ability 15%
3. Follow ethical practices 5%
Product related (15 Marks) 70%
4. Interactive GUI 20%
5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total (25 Marks) 100%
List of student Team Members
1
2
3
4
Marks Obtained Dated signature of
Teacher
Process Product Total
Related(10) Related(15) (25)
Maharashtra State Board of Technical Education 7