Unit 1 of 4 · B.Sc IT Sem 6

Unit 1: Android fundamentals

Mobile Application Development notes · PTU syllabus (BSIT601)

3 min read8 topics10 exam questions
On this page
  1. Unit summary
  2. Overview of Java and Android
  3. Android compared with other environments
  4. The Android software stack
  5. Application structure
  6. The application context
  7. Intents
  8. Activity life cycle
  9. Supporting multiple screen sizes
  10. Key terms
  11. Quick revision
  12. Important questions

Unit summary

Android runs on most of the world's smartphones, and its apps are written in Java or Kotlin. This unit covers an overview of Java and Android, how Android compares with other mobile environments, the Android software stack and application structure, the application context, intents, the activity life cycle, and supporting multiple screen sizes.

After this unit you can

  • Relate Java to Android development and compare mobile platforms
  • Describe the Android stack and the structure of an app
  • Use context and intents
  • Explain the activity life cycle and design for multiple screens

PTU syllabus topics

  • Overview of Java and Android
  • comparison with other environments
  • Android stack and application structure
  • application context
  • intents
  • activity life cycle
  • supporting multiple screen sizes
CycleAndroid activity life cycle
Android activity life cycle
1onCreate()
2onStart()
3onResume()
4onPause()
5onStop()
6onDestroy()
  1. 1. onCreate(): Set up the screen
  2. 2. onStart(): Becomes visible
  3. 3. onResume(): User can interact
  4. 4. onPause(): Partly hidden
  5. 5. onStop(): No longer visible
  6. 6. onDestroy(): Activity closed
1

Topic 1

Overview of Java and Android

  • Android: an open-source, Linux-based mobile operating system led by Google (Android Inc. acquired 2005; first phone 2008). Apps are written in Java or Kotlin (Google's preferred language since 2019) and built with Android Studio (which replaced Eclipse with the ADT plug-in).
  • Java concepts used constantly: classes and inheritance (an Activity extends AppCompatActivity), interfaces (listeners such as View.OnClickListener), anonymous classes and lambdas, generics (ArrayList of String), exceptions and packages.
ProcessAndroid build process
  1. 1

    Java or Kotlin source and XML resources

  2. 2

    Compiled to bytecode

  3. 3

    Converted to DEX (Dalvik executable) by D8

  4. 4

    Packaged with resources and manifest into an APK or App Bundle

  5. 5

    Signed

  6. 6

    Installed and run on ART (Android Runtime)

2

Topic 2

Android compared with other environments

ComparisonMobile platforms
Android
iOS

Developer

Google and Open Handset Alliance

Apple

Source

Open source (AOSP)

Closed

Languages

Kotlin, Java

Swift, Objective-C

IDE

Android Studio (any OS)

Xcode (macOS only)

Devices

Many manufacturers, screen sizes and versions (fragmentation)

Limited Apple devices

Store

Google Play and others; side-loading allowed

App Store only (with regional exceptions)

  • Cross-platform options: Flutter (Dart), React Native (JavaScript), Kotlin Multiplatform; web apps and PWAs run in the browser.
3

Topic 3

The Android software stack

HierarchyAndroid architecture
  1. Applications

    Phone, contacts, browser, your apps

  2. Java API framework

    Activity manager, content providers, resource manager, notification manager, view system, location manager

  3. Native C/C++ libraries and Android Runtime

    SQLite, OpenGL ES, WebKit, media; ART with ahead-of-time and JIT compilation

  4. Hardware abstraction layer

    Standard interfaces to camera, Bluetooth, sensors

  5. Linux kernel

    Drivers, memory and process management, security, power management

4

Topic 4

Application structure

ClassificationAndroid project structure
App module
  • manifests/AndroidManifest.xml

    Package name, components, permissions, launcher activity

  • java (or kotlin)

    Activities, adapters, helper classes

  • res/layout

    XML screen layouts

  • res/values

    strings.xml, colors.xml, themes

  • res/drawable and mipmap

    Images and app icons

  • Gradle scripts

    build.gradle — SDK versions and dependencies

FrameworkApplication components
  • Activities

    Single screens with a user interface

  • Services

    Background work without a UI — music playback

  • Broadcast receivers

    Respond to system-wide events — battery low, SMS received

  • Content providers

    Share data between apps — contacts

xml<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:label="@string/app_name" android:icon="@mipmap/ic_launcher">
        <activity android:name=".MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
5

Topic 5

The application context

  • Context: an interface to global information about the app environment — used to access resources, start activities and services, get system services, open databases and files, and show toasts.
ComparisonTypes of context
Application context
Activity context

Obtained by

getApplicationContext()

this inside an activity

Lifetime

Whole app process

Only while that activity lives

Use for

Long-lived objects — database helpers, singletons

UI work — dialogs, layout inflation, starting activities

Risk

Cannot show themed UI

Memory leaks if stored in long-lived objects

6

Topic 6

Intents

  • Intent: a messaging object requesting an action from another component — start an activity, start a service or deliver a broadcast.
ComparisonExplicit and implicit intents
Explicit intent
Implicit intent

Target

Names the exact component class

Declares an action; the system finds a suitable app

Use

Navigating within your own app

Opening a web page, dialling, sharing, taking a photo

Example

new Intent(this, ResultActivity.class)

new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.sbs.ac.in"))

java// Explicit: open ResultActivity and pass data
Intent i = new Intent(MainActivity.this, ResultActivity.class);
i.putExtra("name", "Riya");
i.putExtra("marks", 91);
startActivity(i);

// In ResultActivity
String name = getIntent().getStringExtra("name");
int marks = getIntent().getIntExtra("marks", 0);

// Implicit: dial a number
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:01612345678")));
  • Intent filters in the manifest declare which implicit intents a component can handle.
7

Topic 7

Activity life cycle

CycleActivity life cycle
Activity life cycle
1onCreate()
2onStart()
3onResume()
4onPause()
5onStop()
6onRestart()
7onDestroy()
  1. 1. onCreate(): Activity created — set layout, initialise views
  2. 2. onStart(): Becoming visible
  3. 3. onResume(): In the foreground, interacting with the user
  4. 4. onPause(): Partly hidden — save light data, pause animations
  5. 5. onStop(): No longer visible — release heavy resources
  6. 6. onRestart(): Coming back from stopped
  7. 7. onDestroy(): Being finished or destroyed by the system

Example

Pressing Home on a running app calls onPause() then onStop(); returning calls onRestart(), onStart(), onResume(). Rotating the screen destroys and recreates the activity unless state is saved (onSaveInstanceState or ViewModel).

8

Topic 8

Supporting multiple screen sizes

Key termsTechniques for multiple screens
Density-independent pixels (dp)
Size layouts in dp and text in sp, not px
Flexible layouts
ConstraintLayout, match_parent, wrap_content, weights
Alternative resources
layout-land, layout-sw600dp for tablets, values-night
Density-specific images
drawable-mdpi, hdpi, xhdpi, xxhdpi or vector drawables
Window size classes
Compact, medium, expanded layouts for phones, foldables and tablets
Key formulasScreen density
  • Pixels from dp

    px = dp × (dpi ÷ 160)

  • Example

    48 dp at 480 dpi (xxhdpi) = 144 px

Key terms

APK
Android package file used to install apps
ART
Android Runtime that executes app code
Activity
Single screen of an Android app
Intent
Message requesting an action from a component
dp
Density-independent pixel for consistent sizing

Quick revision

  • Android history; Java/Kotlin; Android Studio; build to DEX and APK.
  • Android vs iOS; cross-platform frameworks.
  • Stack: kernel, HAL, native libraries and ART, framework, apps.
  • Project structure; manifest; activities, services, receivers, providers; context.
  • Explicit vs implicit intents; life-cycle callbacks; dp, sp, alternative resources.

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.Name the layers of the Android stack.
  2. Q2.What is the AndroidManifest.xml file?
  3. Q3.Distinguish application context and activity context.
  4. Q4.Distinguish explicit and implicit intents.
  5. Q5.Which callback runs when an activity becomes visible?
  6. Q6.Why should layouts use dp instead of px?

Long-answer questions

  1. Q1.Explain the Android architecture with a diagram.
  2. Q2.Explain the structure of an Android application and its components.
  3. Q3.Explain intents with examples.
  4. Q4.Explain the activity life cycle with a diagram.

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