How do I get extra data from intent on Android?

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

    Add-up

    Set Data

    String value = "Hello World!";
    Intent intent = new Intent(getApplicationContext(), NewActivity.class);
    intent.putExtra("sample_name", value);
    startActivity(intent);
    

    Get Data

    String value;
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        value = bundle.getString("sample_name");
    }
    

提交回复
热议问题