Transfer data from one Activity to Another Activity Using Intents

后端 未结 8 1608
花落未央
花落未央 2020-11-29 06:36

I would like to be able to transfer data from one activity to another activity. How can this be done?

8条回答
  •  忘掉有多难
    2020-11-29 07:11

    This works best:

    Through the below code we can send the values between activities

    use the below code in parent activity(PARENT CLASS/ VALUE SENDING CLASS)

    Intent myintent=new Intent(.this,.class).putExtra("", value);
    startActivity(myintent);
    

    use the below code in child activity(TARGET CLASS/ACTIVITY)

    String s= getIntent().getStringExtra();
    

    Please see here that "StringName" is the name that the destination/child activity catches while "value" is the variable name, same as in parent/target/sending class.

提交回复
热议问题