Mobile Application Development Lab
1. Create a simple “Hello World” application in Android.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="30sp"
android:layout_centerInParent="true" />
</RelativeLayout>
MainActivity.java
package com.example.helloworld;
import androidx.appcompat.app.*;
import android.os.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
2. Create a simple "Click Me" application in Android.
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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.myapplicationkrsend;
import androidx.appcompat.app.*;
import android.os.*;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.hello).setOnClickListener(v ->
Toast.makeText(this, "Hey! We are using Android Application",
Toast.LENGTH_SHORT).show());
3. Create an application that displays a message based on the
screen orientation.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/por"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Portrait"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/lan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Landscape"
android:layout_below="@id/por"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
MainActivity.java
package com.example;
import android.content.pm.*;
import android.os.*;
import android.widget.*;
import androidx.appcompat.app.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button por = findViewById(R.id.por);
Button lan = findViewById(R.id.lan);
lan.setOnClickListener(v ->
changeOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, "Hey! We are
in Landscape orientation"));
por.setOnClickListener(v ->
changeOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, "Hey! We are in
Portrait orientation"));
private void changeOrientation(int orientation, String message) {
setRequestedOrientation(orientation);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
4. Create an application to develop a login window using UI
controls.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/username"
android:hint="Username"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/password"
android:hint="Password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/loginBtn"
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java
package com.example.loginapp;
import android.os.*;
import android.widget.*;
import androidx.appcompat.app.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText user = findViewById(R.id.username);
EditText pass = findViewById(R.id.password);
Button login = findViewById(R.id.loginBtn);
login.setOnClickListener(v -> {
String u = user.getText().toString();
String p = pass.getText().toString();
Toast.makeText(this, ":User " + u + ", Pass: " + p,
Toast.LENGTH_SHORT).show();
});
}
5. Create an application to implement a new activity using:
o Explicit intent
o Implicit intent
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Implicit Intent"
android:onClick="onImplicitButtonClicked" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Explicit Intent"
android:onClick="onExplicitButtonClicked" />
</LinearLayout>
MainActivity.java
package com.example.myapplication4;
import android.content.*;
import android.net.*;
import android.os.*;
import androidx.appcompat.app.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onImplicitButtonClicked(View view) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.com")));
}
public void onExplicitButtonClicked(View view) {
startActivity(new Intent(this, MainActivity.class));
}
}
6. Create an application to send an email.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="24dp"
android:orientation="vertical">
<EditText
android:id="@+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editTextSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject" />
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Message"
android:inputType="textMultiLine" />
<Button
android:id="@+id/buttonSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
MainActivity.java
package com.example.email;
import android.content.*;
import android.net.*;
import android.os.*;
import android.widget.*;
import androidx.appcompat.app.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText email = findViewById(R.id.editTextEmail);
Button send = findViewById(R.id.buttonSend);
send.setOnClickListener(v -> {
String e = email.getText().toString();
if (e.isEmpty()) {
Toast.makeText(this, "Enter email", Toast.LENGTH_SHORT).show();
return;
startActivity(Intent.createChooser(new Intent(Intent.ACTION_SENDTO,
Uri.parse("mailto:" + e))
.putExtra(Intent.EXTRA_SUBJECT, ((EditText)
findViewById(R.id.editTextSubject)).getText().toString())
.putExtra(Intent.EXTRA_TEXT, ((EditText)
findViewById(R.id.editTextMessage)).getText().toString()), "Choose Email App"));
});
}
7. Learn to Deploy Android Applications.
(Publishing your Android Application).
Step-by-Step Guide to Publishing an Android App
on the Google Play Store
Step 1: Prepare the App for Release
1. Testing
- Test on various devices, screen sizes, and Android versions.
- Ensure smooth UX and performance under different conditions.
2. Optimization
- Minimize APK/AAB size.
- Use ProGuard or R8 for code shrinking and obfuscation.
3. Security
- Patch vulnerabilities.
- Secure APIs, encrypt storage, and protect user data.
4. Compliance
- Follow Google Play Developer Policies.
5. Update Version Info
Edit build.gradle:
android {
defaultConfig {
versionCode 2
versionName "1.1"
6. Check Permissions
In AndroidManifest.xml:
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
...
</manifest>
Step 2: Generate Signed APK or AAB
In Android Studio:
- Go to Build > Generate Signed Bundle / APK
- Choose APK or Android App Bundle (AAB) and click Next
- Provide:
- Keystore path
- Passwords and alias (or create new)
- Developer info (Name, City, Country)
- Select release build and click Finish
Your signed APK/AAB will be generated.
Step 3: Create a Google Play Developer Account
- Go to https://play.google.com/console
- Sign in with your Google account
- Pay a 25 USD one-time fee
- Fill in:
- Developer name (public)
- Email and phone
- Identity verification
Step 4: Upload App on Google Play Console
1. Log in and click Create App
2. Enter:
- App title
- Default language
- Developer details
3. Fill in Store Listing:
- Short and Full descriptions
- Screenshots (Phone, Tablet, etc.)
- App Icon: 512x512 px
- Feature Graphic: 1024x500 px
4. Upload Signed APK/AAB
5. Set:
- Pricing (Free or Paid)
- Countries to distribute
6. Save and click Publish
8. Create a sample application with login module(check user name and
password) On successful login change TextView “Login Successful”. On login
fail alert using toast “Login Fail”.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/username"
android:hint="Username"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/password"
android:hint="Password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/loginBtn"
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java
package com.example.login;
import android.os.*;
import android.widget.*;
import androidx.appcompat.app.*;
public class MainActivity extends AppCompatActivity {
private EditText usernameInput, passwordInput;
private TextView loginStatus;
private static final String USER = "user", PASS = "password";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameInput = findViewById(R.id.username);
passwordInput = findViewById(R.id.password);
loginStatus = findViewById(R.id.loginBtn);
findViewById(R.id.loginBtn).setOnClickListener(v -> validateLogin());
private void validateLogin() {
if (usernameInput.getText().toString().equals(USER) &&
passwordInput.getText().toString().equals(PASS)) {
loginStatus.setText("Login Successful");
Toast.makeText(this, "Login Successful", Toast.LENGTH_SHORT).show(); //
Added Toast for successful login
} else {
Toast.makeText(this, "Login Failed", Toast.LENGTH_SHORT).show();