user16482035
user16482035

Reputation:

Android activities with Kotlin and Java

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?

Upvotes: 1

Views: 1817

Answers (2)

Levon
Levon

Reputation: 1691

Yes, it's possible to mix Java and Kotlin activities in the same Android project.

On the top menu of Android Studio click File, then New, then Activity, and select any activity. You will see a dialog like this:

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.

Upvotes: 0

Fred B.
Fred B.

Reputation: 1721

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:

Upvotes: 2

Related Questions