Unit 2 of 4 · B.Sc IT Sem 6

Unit 2: UI widgets and data storage

Mobile Application Development notes · PTU syllabus (BSIT601)

3 min read10 topics10 exam questions
On this page
  1. Unit summary
  2. Text and button controls
  3. Toggle buttons and images
  4. Notifications and toasts
  5. Menus and dialogs
  6. Custom lists
  7. Google Maps and GPS location
  8. Shared preferences
  9. File access
  10. SQLite database (overview)
  11. View and drawable animation
  12. Key terms
  13. Quick revision
  14. Important questions

Unit summary

Users interact through widgets, and apps must remember data. This unit covers text and button controls, toggle buttons, images, notifications and toasts, menus and dialogs, custom lists, Google Maps and GPS location, shared preferences, file access, SQLite, and view and drawable animation.

After this unit you can

  • Build user interfaces with common widgets
  • Show toasts, notifications, menus and dialogs
  • Create custom lists and use maps and location
  • Store data in preferences, files and SQLite and add animations

PTU syllabus topics

  • Text and button controls
  • toggle buttons
  • images
  • notifications and toast
  • menus and dialogs
  • custom lists
  • Google Maps and GPS location
  • shared preferences
  • file access
  • SQLite database
  • view and drawable animation
ClassificationAndroid data storage options
Storing data
  • Shared preferences

    Small key-value settings

  • Internal storage

    Private files

  • External storage

    Shared files, media

  • SQLite

    Structured local database

  • Network

    Web services, cloud

1

Topic 1

Text and button controls

xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:padding="16dp"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <TextView android:text="Student name" android:textSize="18sp"
        android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <EditText android:id="@+id/etName" android:hint="Enter name" android:inputType="textPersonName"
        android:layout_width="match_parent" android:layout_height="wrap_content"/>
    <Button android:id="@+id/btnGreet" android:text="Greet"
        android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
javaEditText et = findViewById(R.id.etName);
Button b = findViewById(R.id.btnGreet);
b.setOnClickListener(v -> Toast.makeText(this, "Hello " + et.getText(), Toast.LENGTH_SHORT).show());
  • Other controls: CheckBox, RadioButton in a RadioGroup, Spinner, SeekBar, ProgressBar, ImageButton.
2

Topic 2

Toggle buttons and images

javaToggleButton tb = findViewById(R.id.tbWifi);          // or Switch / SwitchMaterial
tb.setOnCheckedChangeListener((btn, on) -> img.setImageResource(on ? R.drawable.bulb_on : R.drawable.bulb_off));

ImageView img = findViewById(R.id.imgLogo);
img.setImageResource(R.drawable.sbs_logo);
img.setScaleType(ImageView.ScaleType.CENTER_CROP);
3

Topic 3

Notifications and toasts

  • Toast: a short message that fades automatically; Snackbar: a message with an optional action at the bottom of the screen.
ProcessShowing a notification
  1. 1Create a notification channel (Android 8+)
  2. 2Request POST_NOTIFICATIONS permission (Android 13+)
  3. 3Build with NotificationCompat.Builder — icon, title, text, priority
  4. 4Add a PendingIntent to open an activity on tap
  5. 5Show with NotificationManagerCompat.notify(id, notification)
javaNotificationCompat.Builder nb = new NotificationCompat.Builder(this, "fees")
        .setSmallIcon(R.drawable.ic_notify)
        .setContentTitle("Fee reminder")
        .setContentText("Semester fee is due on 15 October")
        .setAutoCancel(true);
NotificationManagerCompat.from(this).notify(1, nb.build());
4

Topic 4

Menus and dialogs

Key termsTypes of menus
Options menu
App bar items — onCreateOptionsMenu and onOptionsItemSelected
Context menu
Long-press on a view — registerForContextMenu
Popup menu
Anchored to a view, for actions related to it
javanew AlertDialog.Builder(this)
    .setTitle("Delete record")
    .setMessage("Are you sure?")
    .setPositiveButton("Yes", (d, w) -> deleteRecord())
    .setNegativeButton("No", null)
    .show();
  • Dialog types: AlertDialog (with list, single or multiple choice), DatePickerDialog, TimePickerDialog, custom dialogs with their own layout, and DialogFragment.
5

Topic 5

Custom lists

ProcessCustom list with an adapter
  1. 1Design a row layout (image and two text views)
  2. 2Create a model class (Course)
  3. 3Write an adapter (ArrayAdapter or RecyclerView.Adapter) that inflates rows and binds data
  4. 4Attach the adapter to a ListView or RecyclerView
  5. 5Handle item clicks
javaString[] courses = {"BCA", "B.Sc IT", "MBA"};
ListView lv = findViewById(R.id.lvCourses);
lv.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, courses));
lv.setOnItemClickListener((p, v, pos, id) -> Toast.makeText(this, courses[pos], Toast.LENGTH_SHORT).show());
  • RecyclerView recycles row views with a ViewHolder and is preferred for long lists.
6

Topic 6

Google Maps and GPS location

ProcessShowing a map and the user's location
  1. 1Add the Maps SDK dependency and an API key
  2. 2Add a SupportMapFragment to the layout
  3. 3In onMapReady add markers and move the camera
  4. 4Request ACCESS_FINE_LOCATION at run time
  5. 5Use FusedLocationProviderClient to get the last or current location
javapublic void onMapReady(GoogleMap map) {
    LatLng sbs = new LatLng(30.90, 75.85);                 // Ludhiana (approximate)
    map.addMarker(new MarkerOptions().position(sbs).title("SBS Ludhiana"));
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(sbs, 14));
}
  • Location sources: GPS (accurate, outdoors, more battery), network (Wi-Fi and cell towers), fused provider (combines them efficiently).
7

Topic 7

Shared preferences

  • Stores small key–value data (settings, login flags) in an XML file private to the app.
javaSharedPreferences sp = getSharedPreferences("settings", MODE_PRIVATE);
sp.edit().putString("user", "riya").putBoolean("darkMode", true).apply();   // save
String user = sp.getString("user", "guest");                              // read with default
8

Topic 8

File access

ComparisonStorage options
Internal storage
External and shared storage

Location

App-private directory

Shared media folders, SD card

Access by other apps

No

Yes, through MediaStore or file pickers

Permission

None

Scoped storage rules from Android 10

Removed on uninstall

Yes

App-specific external files yes; shared media no

javatry (FileOutputStream fos = openFileOutput("notes.txt", MODE_PRIVATE)) {
    fos.write("Lab 5 completed".getBytes());
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(openFileInput("notes.txt")))) {
    String line = br.readLine();
}
9

Topic 9

SQLite database (overview)

  • SQLite: a lightweight, serverless, file-based relational database built into Android — ideal for structured app data such as student records or expenses. Details are in Unit 4.
10

Topic 10

View and drawable animation

ComparisonAnimation types
How it works
Example

View (tween) animation

Transforms a view: alpha, scale, translate, rotate — defined in res/anim XML

Fade in a logo

Drawable (frame) animation

Shows a sequence of images like a flip book — animation-list XML

Loading spinner

Property animation

Changes any object property over time — ObjectAnimator, ValueAnimator

Move a button and change its colour

javaAnimation fade = AnimationUtils.loadAnimation(this, R.anim.fade_in);   // view animation
logo.startAnimation(fade);

ImageView iv = findViewById(R.id.ivRun);                                // drawable animation
iv.setBackgroundResource(R.drawable.run_frames);
((AnimationDrawable) iv.getBackground()).start();

Key terms

Widget
User interface control such as a button or text box
Toast
Brief pop-up message that disappears automatically
Adapter
Bridge between data and a list view
SharedPreferences
Key–value storage for small data
Frame animation
Animation showing images in sequence

Quick revision

  • TextView, EditText, Button, CheckBox, RadioButton, ToggleButton, ImageView.
  • Toasts, Snackbars, notification channels and builder.
  • Options, context and popup menus; AlertDialog and pickers.
  • Custom lists with adapters; RecyclerView; Maps SDK and fused location.
  • SharedPreferences, internal and external files, SQLite; view, drawable and property animation.

Important exam questions

Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).

Short-answer questions

  1. Q1.Distinguish a toast and a notification.
  2. Q2.What is a notification channel?
  3. Q3.Distinguish options and context menus.
  4. Q4.What is an adapter?
  5. Q5.When are shared preferences used?
  6. Q6.Distinguish view and drawable animation.

Long-answer questions

  1. Q1.Explain common UI widgets with an example layout.
  2. Q2.Explain notifications, menus and dialogs.
  3. Q3.Explain custom lists and Google Maps integration.
  4. Q4.Explain data storage options in Android.

Stuck on this unit?

Message SBS on WhatsApp for help with Mobile Application Development, or to ask about studying B.Sc IT at Synetic.

WhatsApp us