Skip to main content

Overview

MainActivity is the primary activity component that serves as the entry point for the Voice to Text Android application. It extends ComponentActivity and sets up the app’s UI using Jetpack Compose.

Class definition

class MainActivity : ComponentActivity()

Methods

onCreate

Initializes the activity and sets up the Compose UI hierarchy.
override fun onCreate(savedInstanceState: Bundle?)
savedInstanceState
Bundle?
Contains the activity’s previously saved state, or null if this is a newly created activity.

Implementation details

The onCreate method performs the following operations:
  1. Edge-to-edge display - Enables edge-to-edge rendering for a modern, immersive UI experience
  2. Theme application - Wraps the UI in VoiceTotextTheme for consistent Material Design styling
  3. Scaffold setup - Uses Material 3 Scaffold with a top app bar and content area
  4. Content composition - Renders the VoiceRecognitionScreen with appropriate padding
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    enableEdgeToEdge()
    setContent {
        VoiceTotextTheme {
            Scaffold(
                modifier = Modifier.fillMaxSize(),
                topBar = { AppBar() }) { innerPadding ->
                VoiceRecognitionScreen(
                    modifier = Modifier.padding(innerPadding)
                )
            }
        }
    }
}
The enableEdgeToEdge() function call ensures that your app’s content extends behind system bars for a modern, immersive experience.

Dependencies

This class depends on the following components:
  • VoiceRecognitionScreen - The main composable that handles voice recognition functionality
  • AppBar - The top app bar composable that displays the app title
  • VoiceTotextTheme - The custom theme that provides Material Design styling

Required imports

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.ui.Modifier

Build docs developers (and LLMs) love