Conversion Java to Kotlin

In this tutorial you will learn about the Conversion Java to Kotlin and its application with practical example.

Intent & Conversion from Java to Kotlin

Intent: As we know that intent is used to redirect one activity to another activity.Intent Facilitate communication between components, It is Used to invoke components. Uses of Intent are: Starting an Activity, Starting a Service ,Delivering a Broadcast etc.
Types of Intent : Explicit Intents, Implicit Intents .
It is briefly discussed in Android tutorial, Please check Android tutorial for more details.

Android studio version 3.0 provide us facilities to convert our Java class to Kotlin class by following some easy steps. Lets see these steps.


Example: With this given example we get understand about conversion and Also we will learn use of Intent in Android with Kotlin. Follow below steps for Conversion.

Step 1st: In below screen I wrote code of activity in java which we used to do before Kotlin.


Step 2nd :Click on “Code” option in menu of Android Studio and go to “Convert Java File to Kotlin File” or simply use shortcut press “Ctrl+Alt+Shift+K” for converting Java file to Kotlin file. Like below Image.


# After Pressing this option it will be doing process for converting Java File to Kotlin.


Step 3rd: In step third the Java file is converted to Kotlin File, Just check below image.


So this was Java file to Kotlin file conversion. I have used two Activities here , First One is MainActivity and Second one is SecondActivity (Converted file).

#MainActivity.kt: The below code is used for Main Activity. below code is used for Second Activity(Before Conversion).

SecondActivity.kt: After conversion of java file to Kotlin file will look like below code.

XML: There are three XML files are used in this project 1st is for Main Activity, 2nd is for Second Activity and 3rd is “Header” File which is used in both XML. Checkout all below.




So we are all set for this code. Guys do not forget to declare Second Activity in “Manifest.xml” file.

Run: Follow all steps and after completion Run your project, you will get Output like below images.






Hopefully this will help you to get conversion of Java file to Kotlin file and also Intent in Kotlin.

In this tutorial we have learn about the Conversion Java to Kotlin and its application with practical example. I hope you will like this tutorial.