Generated by GPT-5-mini| Activity (Android) | |
|---|---|
| Name | Activity (Android) |
| Developer | |
| Released | 2008 |
| Programming language | Java (programming language), Kotlin (programming language) |
| Operating system | Android (operating system) |
| License | Apache License |
Activity (Android) is a core component of Android (operating system) that provides a single, focused screen with which a user can interact to perform an action. Activities form the building blocks of applications distributed via Google Play and interact with system services such as the Android Runtime and the Linux kernel to manage UI, lifecycle, and resources. Developers typically implement activities using Java (programming language) or Kotlin (programming language) and declare them in an AndroidManifest.xml file for integration with features like intents, BroadcastReceiver, and services.
An activity represents a visual user interface tied to an application's task and window managed by the WindowManager and displayed in the System UI provided by Android (operating system). Activities are subclasses of android.app.Activity and often use components from libraries such as AndroidX and Jetpack (Android) including Android Jetpack Navigation and ViewModel to coordinate UI and data. Activities must be registered in AndroidManifest.xml to handle entry points like intents and ActivityResultLauncher patterns introduced alongside modern AndroidX Activity components.
The activity lifecycle is governed by callback methods defined in android.app.Activity, including onCreate, onStart, onResume, onPause, onStop, onRestart, and onDestroy. The lifecycle integrates with system components such as process lifecycle policies from Android Runtime and memory management via the Linux kernel to reclaim resources when an activity enters the background. Lifecycle-aware components from Android Architecture Components like LiveData and ViewModel respond to lifecycle events to manage UI-related data, while WorkManager and JobScheduler coordinate background work independent of activity state. Activities participate in task stacks managed by the ActivityManager and can be affected by system events such as low-memory conditions tied to Android System WebView usage or Chrome webviews embedded in apps.
Activities are launched via intents that can be explicit or implicit and carry actions, categories, data URIs, and extras to convey context between components. The task model uses affinity, launch modes (standard, singleTop, singleTask, singleInstance), and intent flags such as FLAG_ACTIVITY_NEW_TASK to control back stack behavior in coordination with the ActivityManager and the TaskStackBuilder helper. Deep linking integrates activities with web standards via Android App Links and Intent filters to support entry points from Google Search, Chrome custom tabs, and other apps. The activity lifecycle and task semantics are critical for compatibility with multi-window features introduced in Android N and refined in later releases by Google.
Activities host a view hierarchy rooted at a View or ViewGroup inflated from XML resources in the res directory and composed of widgets from frameworks like Material Design libraries and AndroidX RecyclerView. UI rendering relies on the Android Graphics stack and hardware acceleration driven by OpenGL or Vulkan (API), with window decor provided by the System UI and themes from Android Material Design guidelines. Developers use tools such as Android Studio and the Layout Editor to design layouts and preview configurations for devices by Samsung Electronics, Google Pixel, and other OEMs. Accessibility features integrate with services like TalkBack and system settings to expose UI elements to users with disabilities.
Activities communicate with other app components (activities, services, broadcast receivers, content providers) via intents, bound services using AIDL or Messenger, and content URIs served by ContentProvider. Inter-process communication is mediated by the Binder IPC mechanism implemented in the Linux kernel and coordinated with Android Runtime security boundaries. Activities may start services for long-running tasks or bind to services provided by system components such as Music Player or NotificationListenerService and exchange data using Parcelable or Serializable objects. Integration with cloud services like Firebase and Google Play Services often involves activity-driven authentication flows for OAuth 2.0 via Google Sign-In.
Activities must handle configuration changes such as screen orientation, locale, font scale, and multi-window mode introduced by Android N and later. Developers can declare configuration handling in AndroidManifest.xml or rely on automatic destruction and recreation, preserving transient UI state with onSaveInstanceState bundles and longer-lived data with ViewModel or persistent storage like Room (persistence library). Resources are selected via qualifiers in the res directory (layout, values, drawable) for device configurations found in devices from Samsung Electronics, Huawei, Xiaomi Inc., and others. Testing across configurations uses emulators and device farms provided by services such as Firebase Test Lab.
Activities run within application sandboxes enforced by Android (operating system) and the Linux kernel with permissions declared in AndroidManifest.xml and requested at runtime per the Android permissions model introduced in Android 6.0 Marshmallow. Sensitive actions like accessing camera, location, contacts, and storage require runtime permission checks using ContextCompat and ActivityCompat helpers and may involve user prompts managed by Google Play Services consent flows. Activities interacting with other apps must validate incoming intents to avoid Intent spoofing and use mechanisms such as PendingIntent with appropriate mutability flags to prevent privilege escalation, while app signing and Google Play Protect help maintain platform integrity.