Question 07: Write a program to accept username and password from the end user using Text View and Edit Text.
Download hole Program / Project code, by clicking following link:
Which of these is not defined as a process state?
a. Non-visible
b. Visible
c. Foreground
d. Background.
The answer is a. Non-visible is not defined as a process state in Android.
In Android, the following process states are defined:
- Foreground: A process is considered to be in the foreground if it is currently interacting with the user, such as if it is running a visible activity or service.
- Visible: A process is considered to be visible if it is running an activity that is partially obscured by another activity.
- Background: A process is considered to be in the background if it is not currently visible to the user but still running, such as if it is running a service.
- Empty: A process is considered to be empty if it does not have any active components running in it.
Programming Code:
Following code write in: MainActivity.java
package com.go2collage.practical_07;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
// variables declaration
private Button b1, b2;
EditText ed1, ed2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// variables initialization
b1 = findViewById(R.id.loginbtn);
b2 = findViewById(R.id.exitbtn);
ed1 = findViewById(R.id.username1);
ed2 = findViewById(R.id.pass2);
// adding listener
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ed1.getText().toString().equals("Admin") &&
ed2.getText().toString().equals("Admin@123")){
Toast.makeText(getApplicationContext(), "Login Successful", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, Dashborad_screen.class);
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(), "Something Went Wrong", Toast.LENGTH_SHORT).show();
}
}
});
// Activity Terminate
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
Following code write in: Dashborad_screen.java
package com.go2collage.practical_07;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Dashborad_screen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashborad_screen);
Button b2 = findViewById(R.id.exitbtn);
// Activity Terminate
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
Following code write in: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="go2collage"
android:textSize="24sp"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_margin="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="50dp"
android:layout_marginBottom="75dp"
android:textAlignment="center"
android:textSize="28sp"
android:textColor="@color/black"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/username1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:importantForAutofill="no"
android:inputType="text"
android:minHeight="48dp"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/pass2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:minHeight="48dp"
tools:ignore="Autofill,HardcodedText" />
<Button
android:id="@+id/loginbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
tools:ignore="HardcodedText,DuplicateSpeakableTextCheck" />
<Button
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="wrap_content"
android:text="Exit"
android:id="@+id/exitbtn"
tools:ignore="HardcodedText" />
</LinearLayout>
Following code write in: activity_dashborad_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="go2collage"
android:textSize="24sp"
android:textAlignment="center"
android:textStyle="bold"
android:layout_margin="20dp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:text="Hello, Pritam Balaji"
android:layout_gravity="center"
android:textSize="22sp"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Welcome to go2collage"
android:layout_gravity="center"
android:textSize="18sp"
android:textColor="@color/black"
android:textAlignment="center"
tools:ignore="HardcodedText" />
<Button
android:layout_width="match_parent"
android:layout_marginTop="100dp"
android:layout_height="wrap_content"
android:text="Exit"
android:id="@+id/exitbtn"
tools:ignore="HardcodedText" />
</LinearLayout>
Output:
0 Comments