0% found this document useful (0 votes)
8 views9 pages

Practical 18 Code With Output

The document contains the code for an Android application with a login feature, consisting of an AndroidManifest.xml file and several Java classes for activities. The MainActivity and LoginActivity handle user input for username and password, validating against hardcoded credentials, and transitioning to a WelcomeActivity upon successful login. The layout files define the user interface for the login and welcome screens.

Uploaded by

Rida Shaikh
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)
8 views9 pages

Practical 18 Code With Output

The document contains the code for an Android application with a login feature, consisting of an AndroidManifest.xml file and several Java classes for activities. The MainActivity and LoginActivity handle user input for username and password, validating against hardcoded credentials, and transitioning to a WelcomeActivity upon successful login. The layout files define the user interface for the login and welcome screens.

Uploaded by

Rida Shaikh
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

OUTPUT:

[Link]:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link].practical18">

<application
android:allowBackup="true"
android:label="Login App"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]">

<!-- Launcher Activity (Login Screen) -->


<activity
android:name=".MainActivity"
android:exported="true">

<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]"
/>
</intent-filter>

</activity>

<!-- Second Activity -->


<activity
android:name=".WelcomeActivity"
android:exported="false" />

</application>

</manifest>
[Link]:
package [Link].practical18;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class LoginActivity extends AppCompatActivity {

EditText etUsername, etPassword;


Button btnLogin;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_login);

etUsername = findViewById([Link]);
etPassword = findViewById([Link]);
btnLogin = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String username = [Link]().toString();
String password = [Link]().toString();

// Simple validation
if ([Link]("admin") && [Link]("1234")) {

Intent intent = new Intent([Link],


[Link]);
[Link]("USERNAME", username);
startActivity(intent);

} else {
[Link]([Link], "Invalid
Credentials", Toast.LENGTH_SHORT).show();
}
}
});
}
}
[Link]
package [Link].practical18;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

EditText etUsername, etPassword;


Button btnLogin;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etUsername = findViewById([Link]);
etPassword = findViewById([Link]);
btnLogin = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {

String username = [Link]().toString();


String password = [Link]().toString();

if ([Link]("admin") && [Link]("1234")) {

Intent intent = new Intent([Link],


[Link]);
[Link]("USERNAME", username);
startActivity(intent);

} else {
[Link]([Link], "Invalid
Credentials", Toast.LENGTH_SHORT).show();
}
}
});
}
}
[Link]
package [Link].practical18;

import [Link];
import [Link];

import [Link];

public class WelcomeActivity extends AppCompatActivity {

TextView txtWelcome;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_welcome);

txtWelcome = findViewById([Link]);

// Get username from LoginActivity


String username = getIntent().getStringExtra("USERNAME");

[Link]("Welcome, " + username + "!");


}
}
activity_login.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:gravity="center"
android:padding="24dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Screen"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="30dp"/>

<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:layout_marginBottom="15dp"/>

<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"/>

<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>

</LinearLayout>
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:gravity="center"
android:padding="24dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Screen"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="30dp"/>

<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:layout_marginBottom="15dp"/>

<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"/>

<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>

</LinearLayout>
Activity_welcome.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:gravity="center"
android:padding="24dp">

<TextView
android:id="@+id/txtWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="24sp"
android:textStyle="bold"/>

</LinearLayout>

You might also like