How do I get extra data from intent on Android?

后端 未结 16 2613
清歌不尽
清歌不尽 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:51

    First, get the intent which has started your activity using the getIntent() method:

    Intent intent = getIntent();
    

    If your extra data is represented as strings, then you can use intent.getStringExtra(String name) method. In your case:

    String id = intent.getStringExtra("id");
    String name = intent.getStringExtra("name");
    

提交回复
热议问题