What is an Activity?
An Activity is a core Android component that provides a window in which the app draws its UI. Typically, one Activity implements one screen in an application. In your Flutter Runner, the MainActivity acts as a canvas where the Flutter Engine renders its widget tree. As an Engineering Manager, you must ensure that your Activities are 'lean'—shifting heavy business logic to ViewModels or background Coroutines.
- The Activity Lifecycle
As a user navigates through, leaves, and returns to your app, the Activity instances in your app transition through different states in their lifecycle. Managing these transitions is critical to prevent memory leaks and ensure a smooth user experience in Chennai's diverse device ecosystem.
- onCreate(): Fired when the system first creates the activity. You perform basic startup logic here (e.g.,
setContentViewor initializing Riverpod-like native state). - onStart(): Makes the activity visible to the user.
- onResume(): The activity enters the foreground and becomes interactive. This is where you start animations or camera previews.
- onPause(): The first indication that the user is leaving the activity. Use this to pause ongoing actions or save small amounts of data.
- onStop(): The activity is no longer visible. You should release heavy resources here.
- onDestroy(): Fired before the activity is destroyed. Final cleanup happens here.
- Launching Activities with Intents
Activities don't call each other directly. Instead, they use an Intent—an abstract description of an operation to be performed. This allows for 'Loose Coupling' between screens.
- Configuration Changes & State
By default, Android destroys and recreates your Activity when a 'Configuration Change' occurs (like rotating the screen). For Revochamp, you must handle this by either using ViewModels to persist data or by overriding onSaveInstanceState() to store the current state of the AI builder.
Activity Role Comparison
| Scenario | Activity Usage | Flutter Equivalent |
|---|---|---|
| Main Entry | MainActivity (Launcher) | main.dart |
| New Screen | Start new Activity via Intent | Navigator.push() |
| Data Persistence | onSaveInstanceState / ViewModel | Hydrated Bloc / Riverpod |
| Resource Cleanup | onStop() / onDestroy() | dispose() method |
| Background Task | Start a Service from Activity | WorkManager / Isolates |