android-kotlin
/

Android Activity – The UI Entry Point & Lifecycle

Last Sync: Today

On this page

5
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

android-kotlin

Android Activity – The UI Entry Point & Lifecycle

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.

  1. 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., setContentView or 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.

  1. 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.

KOTLINRead-only
1
// Launching a native AI Preview Activity from your Flutter Bridge
val intent = Intent(this, AIPreviewActivity::class.java).apply {
    putExtra("TEMPLATE_ID", "revo_99")
}
startActivity(intent)

  1. 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

ScenarioActivity UsageFlutter Equivalent
Main EntryMainActivity (Launcher)main.dart
New ScreenStart new Activity via IntentNavigator.push()
Data PersistenceonSaveInstanceState / ViewModelHydrated Bloc / Riverpod
Resource CleanuponStop() / onDestroy()dispose() method
Background TaskStart a Service from ActivityWorkManager / Isolates

Test Your Knowledge

Q1
of 3

Which lifecycle method is called when the Activity is no longer visible to the user but not yet destroyed?

A
onPause()
B
onStop()
C
onDetach()
D
onHide()
Q2
of 3

What object is used to request the launch of another Activity?

A
Context
B
Messenger
C
Intent
D
Router
Q3
of 3

In which lifecycle method should you initialize your UI and set the content view?

A
onStart()
B
onResume()
C
onCreate()
D
onAttach()

Frequently Asked Questions

What is the 'Context' in an Activity?

The Activity class inherits from 'Context'. It is a handle to the system; it allows you to access resources (strings, images), launch other activities, and interact with system services. In Flutter Method Channels, you often pass the 'Activity Context' to native plugins.

Why is my Activity recreating when I rotate the phone?

Android triggers a configuration change to reload resources (like landscape-specific layouts). To prevent this in a Flutter app, the Manifest usually includes 'android:configChanges="orientation|screenSize|smallestScreenSize"', which tells the OS that the app will handle these changes manually.

How do I get a result back from a launched Activity?

In 2026, we use the 'Activity Result API' (registerForActivityResult). This replaces the deprecated 'startActivityForResult' and provides a type-safe way to receive data back from a native screen.

Previous

android manifest

Next

android fragments

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.