Courses / Mobile Application Development (CDE-315) – BS CS 5th Semester
Week 17 Lab 17 – Campus Feedback App: Form, 10-Second Countdown, Current Location and Email
Week 17 – Performance, Power, Platform Constraints and Emerging Technologies · 240 min read · 8 MCQs to check yourself
Objective
Combine what you built in Labs 7, 10, 11, 13 and 15 into one complete feature: a Campus Feedback screen where a student sends a complaint or suggestion by email, with the current location attached, a 10-second countdown (undo window) and a success message. CLOs: CLO-2 (develop a complete app), CLO-3 (permissions, battery, lifecycle trade-offs), CLO-4 (solve a real campus problem with modern tools).
What you will build in CampusMate
FeedbackActivity:
┌─────────────────────────────┐
│ Campus Feedback │
│ Name [Ali Raza ] │ ← remembered (Lab 10)
│ Roll No [BSCS-23-014 ] │
│ (•) Complaint ( ) Suggestion│ ← RadioGroup (Lab 7)
│ Area [Library ▼] │ ← Spinner
│ Message [............ ] │
│ 📍 33.684400, 73.047900 ±12 m│ ← location (Lab 15)
│ [Refresh location] │
│ [ SUBMIT ] │
│ Sending in 07 s [Cancel] │ ← countdown (Lab 13)
└─────────────────────────────┘
↓ countdown ends
Email app opens (Lab 11) → back → "Thank you!" dialog
| Lab reused | Used for |
|---|---|
| 7 – Registration form | Form, RadioGroup, validation with setError |
| 10 – SharedPreferences | Remember name and roll number |
| 11 – Email intent | ACTION_SENDTO + mailto: with To/Subject/Body |
| 13 – CountDownTimer | 10-second undo window |
| 15 – Location | FusedLocationProviderClient + permission |
Workflow
| Step | What you do | File |
|---|---|---|
| 1 | Dependency, permissions, activity | build.gradle.kts, manifest |
| 2 | Strings and the areas array | res/values/strings.xml |
| 3 | Form layout | activity_feedback.xml |
| 4 | Fields, launchers, onCreate | FeedbackActivity.java |
| 5 | Location (permission + getCurrentLocation) | fetchLocation() |
| 6 | Validate and start the 10-second countdown | submit() |
| 7 | Build and open the email | openEmail() |
| 8 | Success dialog and remember the student | showSuccess() |
| 9 | Test plan, report and viva | – |
Step 1 – Setup
- Dependency (already added in Lab 15):
implementation("com.google.android.gms:play-services-location:21.3.0") - Manifest permissions (already there from Lab 15):
ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION. - No INTERNET or SEND_SMS permission is needed – the email app sends the message.
- New → Activity → Empty Views Activity →
FeedbackActivity(Java); open it from the Home tab.
Step 2 – Strings and arrays (res/values/strings.xml)
Add inside <resources>:
<string name="admin_email">admin@uni.edu.pk</string>
<string-array name="areas">
<item>Library</item>
<item>Computer Labs</item>
<item>Classrooms</item>
<item>Hostel</item>
<item>Cafeteria</item>
<item>Transport</item>
<item>Washrooms</item>
<item>Other</item>
</string-array>
Step 3 – Layout (activity_feedback.xml)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Campus Feedback" android:textSize="24sp" android:textStyle="bold" />
<EditText android:id="@+id/etName"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:hint="Name" android:inputType="textPersonName" />
<EditText android:id="@+id/etRoll"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:hint="Roll No (e.g. BSCS-23-014)" />
<RadioGroup android:id="@+id/rgType"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="@+id/rbComplaint"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:text="Complaint" />
<RadioButton android:id="@+id/rbSuggestion"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Suggestion" />
</RadioGroup>
<Spinner android:id="@+id/spArea"
android:layout_width="match_parent" android:layout_height="48dp"
android:entries="@array/areas" />
<EditText android:id="@+id/etMessage"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="top" android:hint="Describe the problem or suggestion"
android:inputType="textMultiLine" android:minLines="3" />
<TextView android:id="@+id/tvLocation"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:text="📍 Location: –" />
<Button android:id="@+id/btnRefresh"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Refresh location" />
<Button android:id="@+id/btnSubmit"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:text="Submit" />
<LinearLayout android:id="@+id/countdownBox"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="center_vertical" android:orientation="horizontal"
android:visibility="gone">
<TextView android:id="@+id/tvCountdown"
android:layout_width="0dp" android:layout_weight="1"
android:layout_height="wrap_content" android:text="Sending in 10 s…" />
<Button android:id="@+id/btnCancel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
</ScrollView>
android:entries="@array/areas" fills the Spinner from the string-array – no adapter code needed.
Step 4 – Fields, launchers and onCreate (FeedbackActivity.java)
package com.example.campusmate;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.*;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.Priority;
import java.util.Locale;
public class FeedbackActivity extends AppCompatActivity {
private EditText etName, etRoll, etMessage;
private RadioGroup rgType;
private Spinner spArea;
private TextView tvLocation, tvCountdown;
private View countdownBox;
private Button btnSubmit;
private SharedPreferences prefs;
private FusedLocationProviderClient fused;
private Location lastLocation; // null = not available
private CountDownTimer timer;
// Lab 15: ask for both location permissions
private final ActivityResultLauncher<String[]> locationPermission =
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), r -> {
if (r.containsValue(true)) fetchLocation();
else tvLocation.setText("📍 Location permission denied – feedback can still be sent");
});
// Lab 4 idea: we come back here when the user returns from the email app
private final ActivityResultLauncher<Intent> emailLauncher =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
result -> showSuccess());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback);
etName = findViewById(R.id.etName);
etRoll = findViewById(R.id.etRoll);
etMessage = findViewById(R.id.etMessage);
rgType = findViewById(R.id.rgType);
spArea = findViewById(R.id.spArea);
tvLocation = findViewById(R.id.tvLocation);
tvCountdown = findViewById(R.id.tvCountdown);
countdownBox = findViewById(R.id.countdownBox);
btnSubmit = findViewById(R.id.btnSubmit);
// Lab 10: restore the remembered student
prefs = getSharedPreferences("student", MODE_PRIVATE);
etName.setText(prefs.getString("name", ""));
etRoll.setText(prefs.getString("roll", ""));
fused = LocationServices.getFusedLocationProviderClient(this);
btnSubmit.setOnClickListener(v -> submit());
findViewById(R.id.btnCancel).setOnClickListener(v -> cancelCountdown());
findViewById(R.id.btnRefresh).setOnClickListener(v -> checkLocation());
checkLocation();
}
// Steps 5–8 below
}
Step 5 – Location (from Lab 15)
private void checkLocation() {
boolean granted = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
== PackageManager.PERMISSION_GRANTED;
if (granted) fetchLocation();
else locationPermission.launch(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION});
}
@SuppressLint("MissingPermission")
private void fetchLocation() {
tvLocation.setText("📍 Getting location…");
fused.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null) // fresh high-accuracy fix
.addOnSuccessListener(loc -> {
lastLocation = loc;
if (loc == null) tvLocation.setText("📍 Location not available");
else tvLocation.setText(String.format(Locale.US, "📍 %.6f, %.6f (±%d m)",
loc.getLatitude(), loc.getLongitude(), Math.round(loc.getAccuracy())));
});
}
If permission is denied, the app still works – the email simply says "Location: not available".
Step 6 – Validate and start the 10-second countdown (from Labs 7 and 13)
private void submit() {
if (etName.getText().toString().trim().isEmpty()) { etName.setError("Enter your name"); return; }
if (etRoll.getText().toString().trim().isEmpty()) { etRoll.setError("Enter your roll number"); return; }
if (etMessage.getText().toString().trim().length() < 10) {
etMessage.setError("Write at least 10 characters"); return;
}
btnSubmit.setEnabled(false); // no double submit
countdownBox.setVisibility(View.VISIBLE);
checkLocation(); // attach the latest location during the countdown
timer = new CountDownTimer(10_000, 1000) {
@Override
public void onTick(long ms) {
tvCountdown.setText("Sending in " + ((ms + 999) / 1000) + " s… tap Cancel to edit");
}
@Override
public void onFinish() {
countdownBox.setVisibility(View.GONE);
openEmail();
}
}.start();
}
private void cancelCountdown() {
if (timer != null) timer.cancel(); // stop the countdown
countdownBox.setVisibility(View.GONE);
btnSubmit.setEnabled(true);
Toast.makeText(this, "Cancelled – edit your feedback", Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy() {
if (timer != null) timer.cancel();
super.onDestroy();
}
The countdown is an undo window: the student can still cancel and edit while the location is being attached.
Step 7 – Build and open the email (from Lab 11)
private void openEmail() {
String name = etName.getText().toString().trim();
String roll = etRoll.getText().toString().trim();
String type = (rgType.getCheckedRadioButtonId() == R.id.rbComplaint) ? "Complaint" : "Suggestion";
String area = spArea.getSelectedItem().toString();
String message = etMessage.getText().toString().trim();
String location = "not available";
if (lastLocation != null) {
double lat = lastLocation.getLatitude(), lng = lastLocation.getLongitude();
location = lat + ", " + lng + "\nMap: https://maps.google.com/?q=" + lat + "," + lng;
}
String subject = "[" + type + "] " + area + " – " + roll; // e.g. [Complaint] Library – BSCS-23-014
String body = "Name: " + name + "\nRoll No: " + roll + "\nType: " + type
+ "\nArea: " + area + "\n\nMessage:\n" + message + "\n\nLocation: " + location;
Intent email = new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto:"));
email.putExtra(Intent.EXTRA_EMAIL, new String[]{getString(R.string.admin_email)});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, body);
try {
emailLauncher.launch(email);
} catch (Exception e) {
btnSubmit.setEnabled(true);
Toast.makeText(this, "No email app found", Toast.LENGTH_SHORT).show();
}
}
Step 8 – Success message and remember the student (from Lab 10)
private void showSuccess() {
prefs.edit()
.putString("name", etName.getText().toString().trim())
.putString("roll", etRoll.getText().toString().trim())
.apply();
etMessage.setText("");
btnSubmit.setEnabled(true);
new AlertDialog.Builder(this)
.setTitle("Thank you!")
.setMessage("Your feedback has been prepared in your email app. The administration will contact you.")
.setPositiveButton("OK", null)
.show();
}
Email apps do not return a reliable result code, so we confirm when the student comes back to the app.
Step 9 – Test plan
| # | Test | Expected result |
|---|---|---|
| 1 | Open first time | Location permission dialog; then coordinates appear |
| 2 | Deny permission | "Location permission denied…"; app still works |
| 3 | Submit with empty name/message | Field errors, no countdown |
| 4 | Valid form → Submit | Countdown 10 → 1, Submit disabled |
| 5 | Cancel at 6 s | Countdown hidden, Toast, form kept |
| 6 | Let it finish | Gmail: To = admin, Subject "[Complaint] Library – BSCS-23-014", body with location and Maps link |
| 7 | Return from Gmail | "Thank you!" dialog, message cleared, name/roll kept |
| 8 | Close and reopen | Name and roll restored |
| 9 | Rotate during countdown | Activity recreated – discuss: keep the timer in a ViewModel (extension) |
Extensions (higher marks)
- Keep the countdown and location in a ViewModel so rotation does not cancel sending.
- Add a toolbar menu (Lab 8) with "History", "About" and "Clear saved name".
- Save sent feedback with Room and list it in a RecyclerView (Lab 12).
- Show the location on an embedded map (Lab 14).
- Build a signed APK (Lab 16) and install it on your phone.
Marking rubric (suggested – 20 marks)
| Criterion | Marks |
|---|---|
| Form UI complete and usable (inputs, spinner, radio, validation) | 4 |
| Current location with proper runtime permission handling | 4 |
| 10-second countdown with cancel and button states | 3 |
| Email opens with correct To/Subject/Body including location and map link | 4 |
| Success message and remembered student details | 2 |
| Code quality (naming, comments, no crashes) + viva | 3 |
Short and long questions
1. (Viva) Which earlier labs did you combine in the Campus Feedback App?
Model answer
Lab 7 (form design and validation), Lab 10 (SharedPreferences to remember name and roll number), Lab 11 (email intent with prefilled fields), Lab 13 (CountDownTimer), Lab 15 (runtime permissions and current location) – and optionally Lab 8 (menu), Lab 14 (map) and Lab 16 (signed APK).
2. (Viva) Explain how the countdown and location work together in your app.
Model answer
When Submit is pressed after validation, a 10-second CountDownTimer starts and disables the Submit button; the student can cancel to edit. If no location is available yet, the app requests it again during the countdown. When onFinish runs, the latest location (coordinates, accuracy, address and a Maps link) is included in the email body.
3. (Viva) Write the intent used to open the email app with the feedback.
Model answer
Intent email = new Intent(Intent.ACTION_SENDTO); email.setData(Uri.parse("mailto:")); email.putExtra(Intent.EXTRA_EMAIL, new String[]{adminEmail}); email.putExtra(Intent.EXTRA_SUBJECT, "[Complaint] Library – BSCS-23-014"); email.putExtra(Intent.EXTRA_TEXT, body); launched with emailLauncher.launch(email) (an ActivityResultLauncher) so a success dialog appears when the student returns.
4. (Viva) How would you make the app work even if the user rotates the phone during the countdown?
Model answer
Move the countdown, form state and location into a ViewModel (keeping the end time) so they survive the configuration change, and observe the remaining time with LiveData in the activity.
This lesson ends with a quiz of 8 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: Week 17 Theory – Performance/Power Trade-offs; Mobile Platform Constraints; Emerging Technologies · Next: Assignment 4 (Weeks 14–17) – Release-Ready Location App with Performance and Power Study
All lessons in Mobile Application Development (CDE-315) – BS CS 5th Semester