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).
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(), start/stop listeners in onResume()/onPause(), and release resources in onStop()/onDestroy().
Project Structure (Quick Map)
| Path | Description |
|---|---|
app/java/…/*.java | Your Java source files (Activities, adapters, helpers). |
app/res/layout/*.xml | UI layouts. |
app/res/values/*.xml | Strings, colors, dimens, styles. |
app/manifest/AndroidManifest.xml | Components, permissions, app metadata. |
app/build.gradle | App module build script, dependencies. |
settings.gradle | Project 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
| Format | What it is | Use |
|---|---|---|
| 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
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).