Kotlin Android start new Activity

后端 未结 17 2306
不知归路
不知归路 2020-12-07 23:33

I want to start another activity on Android but I get this error:

Please specify constructor invocation; classifier \'Page2\' does not have a companio

17条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 00:17

    You can use both Kotlin and Java files in your application.

    To switch between the two files, make sure you give them unique < action android:name="" in AndroidManifest.xml, like so:

                
                    
                        
                        
                        
                        
                    
                
                
                    
                        
                        
                    
                
    

    Then in your MainActivity.kt (Kotlin file), to start an Activity written in Java, do this:

           val intent = Intent("com.genechuang.basicfirebaseproject.JavaActivity")
            startActivity(intent)
    

    In your MainActivityJava.java (Java file), to start an Activity written in Kotlin, do this:

           Intent mIntent = new Intent("com.genechuang.basicfirebaseproject.KotlinActivity");
            startActivity(mIntent);
    

提交回复
热议问题