Passing a Bundle on startActivity()?

后端 未结 6 1362
攒了一身酷
攒了一身酷 2020-11-22 03:28

What\'s the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?

6条回答
  •  梦如初夏
    2020-11-22 04:23

    Write this is the activity you are in:

    Intent intent = new Intent(CurrentActivity.this,NextActivity.class);
    intent.putExtras("string_name","string_to_pass");
    startActivity(intent);
    

    In the NextActivity.java

    Intent getIntent = getIntent();
    //call a TextView object to set the string to
    TextView text = (TextView)findViewById(R.id.textview_id);
    text.setText(getIntent.getStringExtra("string_name"));
    

    This works for me, you can try it.

    Source:https://www.c-sharpcorner.com/article/how-to-send-the-data-one-activity-to-another-activity-in-android-application/

提交回复
热议问题