Home > Back-end >  How to call a class that is in Kotlin format, through Intent in Java?
How to call a class that is in Kotlin format, through Intent in Java?

Time:09-17

I'm doing a project that has two classes: a Java class called a and another Kotlin class called b. In Java's MainActivity, I want to go to the class called b.kt So how do you do this through Intent? I've tried it in several ways, such as:

startActivity(new Intent(getApplicationContext(), b.kt));

startActivity(new Intent(getApplicationContext(), b::class.kt));

startActivity(new Intent(getApplicationContext(), b.kt.class));

But error always happens. Please, can anyone help me?

CodePudding user response:

It would be b.class. From the Java point of view, it doesn't even know if the class is a Kotlin class or a Java class, so the syntax is the same as if it's a Java class.

Also, the b class should be a subclass of Activity.

By the way, it is convention to always start class names with a capital letter. If you follow the conventions, it will make your code easier to understand and you'll be less likely to make mistakes.

  • Related