main

square/leakcanary

Last updated at: 29/12/2023 09:39

MainActivity.kt

TLDR

The MainActivity class is the main activity of the LeakCanary app. It sets the content of the activity to a Compose view, initializes the backstack view model, and displays the ScreenHost view.

Classes

MainActivity

The MainActivity class is the main activity of the LeakCanary app. It extends ComponentActivity and is annotated with @AndroidEntryPoint. In the onCreate method, it initializes the backstack view model and sets the content of the activity to a Compose view, which displays the ScreenHost view.

Methods

This file does not contain any additional methods.

package org.leakcanary

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModelProvider
import dagger.hilt.android.AndroidEntryPoint
import org.leakcanary.screens.BackStackViewModel
import org.leakcanary.screens.ScreenHost
import org.leakcanary.ui.theme.MyApplicationTheme

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    // Dumb hack to ensure the backstack is created early enough in the activity
    // graph so that BackStackHolder will always have a ref.
    ViewModelProvider(this)[BackStackViewModel::class.java]

    setContent {
      MyApplicationTheme {
        Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
          ScreenHost()
        }
      }
    }
  }
}