1

Can I do this below prossess in android studio?

I have a Kotlin project that I create another activity with its Java class and I want to start activity of Kotlin with clicking botton in activity of java then it start Kotlin activity

irajDP
  • 31
  • 1
  • 7

3 Answers3

2

Kotlin is interoperable with Java. Just start the activity using an Intent like you would normally do in Java.

Chrisvin Jem
  • 3,940
  • 1
  • 8
  • 24
  • I wrote up code but show me error. my cod is [ intent i =new intent(this, MainActivity.class);startActivity(i); ] and show red error on startActivity(i) and compiler show to create its function!! – irajDP Jul 10 '19 at 20:22
  • @irajDP Make sure that your kotlin activity has been added in the manifest, also try `File -> Invalidate Caches/ restart`, `Clean Project` & `Rebuild Project`. Also, as suggested by aaroncio, add your code to the question along with the exact error message that you get (incase the previous steps didn't fix your issue). – Chrisvin Jem Jul 10 '19 at 20:32
1

Yes you can start activity from java to Kotlin and vice versa.

from java

startActivity(new Intent(context,DestinationActivity.class))

from kotlin

startActivity(Intent(this, DestinationActivity::class.java))
Hardik Bambhania
  • 1,732
  • 15
  • 25
0

in java, it is

 startActivity(new Intent(currentActivity.this, nextActivity.class);

if you want to send data to the next activity in java

 Intent intent = new Intent(MainActivity.this, nextActivity.class);

 intent.putExtra("anyName", value);

 startActivity(intent);

for kotlin it is

startActivity(Intent(this@MainActivity, nextActivity::class.java)

if you want to send data to the next activity in kotlin

        val intent = Intent(this@MainActivity, SecondActivity::class.java)
        intent.putExtra("Name", name)
        intent.putExtra("Email", email)
        intent.putExtra("Phone", phone)
        startActivity(intent)
YZN
  • 133
  • 1
  • 8