An Activity represents a single, focused screen in an Android app. Every Activity has a layout — typically an XML file describing the UI — and a Kotlin class controlling its behavior.

<!-- res/layout/activity_main.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <TextView
        android:id="@+id/greetingText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello, Android!" />

</LinearLayout>
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

The Activity lifecycle

An Activity moves through a well-defined set of states as the user interacts with it and the system manages memory:

onCreate() onStart() onResume() [Running] onPause() onStop() onDestroy() onRestart() → onStart()

onCreate() runs once, when the Activity is first created — this is where you call setContentView. onPause()/onStop() run when the user navigates away, and the system may call onDestroy() at any point after that to free memory. Understanding this flow matters because it’s exactly where beginners commonly introduce memory leaks or crashes — for example, starting a long-running task in onCreate() without stopping it in onPause().