Android: How to pass the data to sub-activities?

后端 未结 3 1403
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 05:36

The main activity includes some variables with set values. I created a sub-activity with the form which has to be filled with the data from main activity so I guess the data

3条回答
  •  再見小時候
    2020-12-09 06:23

    Try this it will work:

    activity1.class:

    Intent i = new Intent(activity1.this,activity2.class);
    
    Bundle b = new Bundle();
    b.putString("name", "your value need to pass here");
    
    i.putExtras(b);
    startActivity(i);
    

    activity2.class:

    Bundle b = this.getIntent().getExtras();
    
    String name = b.getString("name");
    
    ((TextView)findViewById(R.id.textView1)).setText(name);
    

提交回复
热议问题