android kotlin 页面跳转

初学- 记录下

https://www.cnblogs.com/MyXcc/p/12881253.html

 

login.setOnClickListener{
            println("----点击登录----")
            var user:String = userInput.text.toString()
            var pwd:String = pwdInput.text.toString()
            var str:String = "用户名:$user, 密码:$pwd  "
            Toast.makeText(applicationContext, str, Toast.LENGTH_SHORT).show()
            
            // 页面跳转
            var intent = Intent()
            intent.setClass(this,HomeActivity().javaClass)
            val bundle = Bundle()
            // 传参
            bundle.putString("text", "Kotlin练习跳转传值")
            intent.putExtras(bundle)
            startActivity(intent)
        }

传参简写:

// 页面跳转 HomeActivity:目标页面Activity
 var intent: Intent = Intent(this, HomeActivity().javaClass) 
// 传参
intent.putExtra("text", "Kotlin练习跳转传值")
startActivity(intent)

 

参数接收:

class HomeActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)
        // 参数接收
        val bundle = this.intent.extras
     // 给TextView 赋值 homeTitle.text
= bundle?.get("text").toString() } }

Activity 需要在 AndroidManifest.xml中注册

 

android kotlin 页面跳转

上一篇:简单C++线程池


下一篇:[译]MongoDb生产环境注意事项