Android Four Major Components
The four major components of Android are the foundational architecture of Android app development: Activity, Service, BroadcastReceiver, and ContentProvider.
1. Activity
- Purpose: Responsible for UI display and user interaction
- Lifecycle: onCreate() → onStart() → onResume() → onPause() → onStop() → onDestroy()
- Usage: Each visible screen is an Activity
2. Service
- Purpose: Performs long-running operations in the background without UI
- Types:
- Started Service: Started via startService(), continues even if starting component is destroyed
- Bound Service: Started via bindService(), requires component binding for interaction
- Usage: Music playback, file download, background sync
3. BroadcastReceiver
- Purpose: Listens and responds to system or app broadcast messages
- Registration:
- Static: Declared in AndroidManifest.xml
- Dynamic: Registered via registerReceiver() in code
- Usage: Network state changes, battery level, boot completion
4. ContentProvider
- Purpose: Shares data between different applications
- Feature: Provides unified URI interface for data access
- Usage: Contact list, media library data sharing
Key Points
- All four components must be registered in AndroidManifest.xml
- Understand lifecycle and communication between components
- Master data transfer mechanisms (Intent, Binder, etc.)