How do I get extra data from intent on Android?

后端 未结 16 2303
清歌不尽
清歌不尽 2020-11-21 11:01

How can I send data from one activity (intent) to another?

I use this code to send data:

Intent i=new Intent(context,SendMessage.class);
i.putExtra(\         


        
16条回答
  •  灰色年华
    2020-11-21 11:44

    Kotlin

    First Activity

    val intent = Intent(this, SecondActivity::class.java)
    intent.putExtra("key", "value")
    startActivity(intent)
    

    Second Activity

    val value = getIntent().getStringExtra("key")
    

    Suggestion

    Always put keys in constant file for more managed way.

    companion object {
        val PUT_EXTRA_USER = "PUT_EXTRA_USER"
    }
    

提交回复
热议问题