Home > Back-end >  Android activities with Kotlin and Java
Android activities with Kotlin and Java

Time:09-24

I read it is possible to use Java and Kotlin classes in android studio. Is it possible to use Java for MainActivity and Kotlin for another activity?

If so, how should I do that?

CodePudding user response:

Kotlin and Java can be used within the same Android Studio project without any problem. They both are compiled into the same bytecode that can be read by the JVM.

To create a basic Kotlin / Java class: Go to Android Studio menu File > New > Java File (or Kotlin File)

To create an Activity class: Go to Android Studio menu, File > New > Activity > Basic Activity (or any other type you may need). Then on the pop up window, change the "source language" to the desired one.

Here a list of useful links for you to read:

  • enter image description here

    Change the Source Language (the last dropdown box) to the desired language, and Android Studio will add a new activity with that language into your project.

  • Related