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

后端 未结 3 1400
佛祖请我去吃肉
佛祖请我去吃肉 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:11

    You can use this method in your main activity

    Intent i = new Intent(this, YourMainClass.class);
    i.putExtra("key", value);
    

    end then in the sub activity get the value with this method, usually in the onCreate event

    int value = getIntent().getExtras().getInt("key");
    

    I hope this hepls.

提交回复
热议问题