Search code examples
androidandroid-studioandroid-jetpack

Android Studio. Migrating Jetpack. Creating additional activities


May be a silly question. I'm new to Android Studio and yet I have an app submmited to Google Play. A very small and basic one But before moving forward I think I should to start migrating to Jetpack architecture. I followed a tutorial from developers.android.com to modify gradles and It seems I successfully added jetpack to my current project. It still builds and run. Nothing broken. The way to convert my out layout activities to UIComponent looks straight forward for now.

I Created a new project of the kind "Empty Compose Activity" for the sake of learning and it gives me a first activity that looks like this.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationJetTheme {
                // A surface container using the 'background' color from the theme
                Surface(color = MaterialTheme.colors.background) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String) {
    Text(text = "Hello $name!")
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    MyApplicationJetTheme {
        Greeting("Android")
    }
}

What confuses to me is that I can't find a way to create the additional activities. Does Android generates class files that inherit from ComponentActivity or should I Create them manually and adding them to the manifest? The similar thing in XCode's swift is quite obvious from the moment you command "New File" but it doesn't seem to be the case in Android Studio

Thank in advance.


Solution

  • Right-click on your project, select New:

    enter image description here

    Then find "Compose" (I haven't update my AS but you get the idea).

    enter image description here

    You can also find this via the "Actions" dialog (Command + Shift + A on Mac) and type "Compose Activity":

    enter image description here