Introduction to Android (Java)

In this introduction, you’ll understand what Android is, how apps are structured, and the core building blocks (Activities, Services, Broadcast Receivers, Content Providers). We’ll also walk through Intents, Lifecycle, Permissions, and how apps are built and packaged.

What is Android?

  • Android OS is a Linux-based operating system for mobile devices (phones, tablets, TVs, wearables).
  • Apps are written primarily in Java or Kotlin and run on the Android runtime (ART).
  • Android provides rich APIs for UI, storage, networking, sensors, camera, location, and more.

Android App Components

Activity

Single screen with UI. Handles user interaction.

Service

Background work with no UI (e.g., music, sync).

Broadcast Receiver

Responds to system/app broadcasts (e.g., battery low).

Content Provider

Shares app data with other apps (structured interface).

These components are declared in AndroidManifest.xml. The OS creates/destroys them as needed.

AndroidManifest.xml (minimal example)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">

    <application android:label="My App">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Intents & Navigation

An Intent is a message to request an action from another component (start an Activity, Service, or deliver a broadcast).

[User clicks a button] └─> Your code creates an Intent (explicit/implicit) └─> startActivity(intent) / startService(intent) / sendBroadcast(intent) └─> System finds the matching component (via manifest & intent-filters) └─> Target component starts and handles the request

Example: Start a new Activity

Intent intent = new Intent(CurrentActivity.this, DetailActivity.class);
startActivity(intent);

Activity Lifecycle (High Level)

The system calls lifecycle methods as the Activity appears/disappears:

onCreate() → first-time initialization (inflate layout, bind views) onStart() → activity becomes visible onResume() → activity comes to foreground, ready for user input [Activity running] onPause() → another activity partially obscures (commit lightweight state) onStop() → activity no longer visible (release resources like receivers) onDestroy() → activity is finishing or being destroyed by system
Tip: Do heavy setup in onCreate(), start/stop listeners in onResume()/onPause(), and release resources in onStop()/onDestroy().

Project Structure (Quick Map)

PathDescription
app/java/…/*.javaYour Java source files (Activities, adapters, helpers).
app/res/layout/*.xmlUI layouts.
app/res/values/*.xmlStrings, colors, dimens, styles.
app/manifest/AndroidManifest.xmlComponents, permissions, app metadata.
app/build.gradleApp module build script, dependencies.
settings.gradleProject settings (modules included).

Permissions (Runtime Model)

Some features need user permission (e.g., camera, location). From Android 6.0 (API 23+), you request them at runtime.

// In AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />

// In Activity (Java) – request at runtime
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
        != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this,
        new String[]{Manifest.permission.CAMERA}, 101);
}

Build Output: APK vs AAB

FormatWhat it isUse
APK (Android Package)Installable package used by devices.Debugging, direct installs.
AAB (Android App Bundle)Publishing format; Play generates optimized APKs.Recommended for Play Store.

Gradle (Build System)

Gradle manages builds, dependencies, flavors, and signing.

android {
    compileSdkVersion 34

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"
    }
}

High-Level Development Flow

Design UI (XML) └─> Write logic (Java) └─> Declare components/permissions (Manifest) └─> Build with Gradle └─> Run on Emulator / Device └─> Test, Debug (Logcat, Profiler) └─> Sign & Publish (APK/AAB)

FAQs

Q. Java or Kotlin? Both are official. We start with Java here; you can follow a parallel Kotlin track later.

Q. Minimum SDK? Choose the lowest version you need to support. API 21 is a common baseline.

Q. Can I test without a phone? Yes, use the Android Emulator (AVD Manager).

Tip: Keep code in Activities lean. Extract logic into helper classes or ViewModels (when you reach the Architecture section).