Skip to main content

What is MainActivity?

On Android, an Activity is the main entry point for interacting with an app. It hosts everything the user sees and handles key logic like launching screens or managing user sessions.

In Cortest, there's a single Kotlin file called MainActivity.kt. It’s responsible for starting the app and managing how users move between different screens.

Thanks to Jetpack Compose, all screens in the app are built using composable functions. These are reusable blocks of UI, defined in the ui/ folder, and they are connected through a central system called the Navigation Graph.


1 - How navigation works

Inside MainActivity.kt, the app sets up a NavController and a NavHost, which together manage the flow between screens — whether you're logging in, launching a test, or changing your settings.

Everything is declared inside a few key components:

2 - MainActivity

This class is the actual entry point of the app. Here's what it does:

  • Handles authentication using Firebase
  • Loads user preferences and patient data
  • Sets the first screen to show (depending on the context)
  • Launches the Compose UI using setContent { ... }
  • Handles external triggers, like widgets, by reacting to incoming intents
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestPermissionsIfNecessary()

setContent {
// Firebase auth, loading patients, checking start screen...
EpilepsyTestApp(...) // Launches the UI
}
}

If the app is opened from a widget (like a shortcut), it updates its intent and restarts itself with the right screen:

MainActivity.kt
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
setIntent(intent)
val startScreen = intent?.getStringExtra("startScreen")
if (!startScreen.isNullOrEmpty()) {
recreate()
}
}

3 - EpilepsyTestApp

This is a composable function that wraps the entire app UI in its theme and initializes the navigation graph.

It checks whether data is still loading and displays either a loading screen or the full app with navigation.

MainActivity.kt
@Composable
fun EpilepsyTestApp(...) {
val navController = rememberNavController()

if (isLoading) {
LoadingScreen()
} else {
AppTheme {
NavigationGraph(
navController = navController,
...
)
}
}
}

4 - NavigationGraph

This composable defines all the app's screens and how to move between them. It uses Jetpack Compose’s NavHost and composable blocks to map out each screen.

MainActivity.kt
@Composable
fun NavigationGraph(...) {
val recordedVideos = remember { mutableStateListOf<String>() }
val cameraViewModel: CameraViewModel = viewModel()

LaunchedEffect(widgetStartScreen) {
widgetStartScreen?.let { target ->
navController.navigate(target) {
popUpTo(navController.graph.startDestinationId) {
inclusive = true
}
launchSingleTop = true
}
}
}

NavHost(
navController = navController,
startDestination = startDestination
) {
composable("home") {
if (isAuthenticated) {
HomePage(...)
} else {
navController.navigate("login") {
popUpTo("home") { inclusive = true }
}
}
}

composable("login") {
LoginScreen(...)
}

// Other screens go here...
}
}

UI Code Structure

All UI screens are defined as composables in files under:

app/src/main/java/com/example/epilepsytestapp/ui

Each file corresponds to a screen or feature of the app:

FileDescription
HomeScreen.ktMain dashboard and navigation bar
DemoScreen.ktInteractive demo of the app
FilesPage.ktList of saved PDFs and videos
SettingsPage.ktApp settings
LoginScreen.ktLogin interface
TypeConfigScreen.ktTest type selection
ConfigScreen.ktTest configuration
RecapConfigScreen.ktTest summary
ConfigHistoryScreen.ktHistory of test setups
SignupScreen.ktSign-up (email & password)
InfoPerso.ktSign-up (personal info)
ProfilePage.ktUser profile
TestScreen.ktActive test screen
ConfirmationScreen.ktTest confirmation screen
TestEnregistre.ktTest saving screen
QuestionnaireScreen.ktPost-test survey