How do you pass data/parameters to another activit

2020-04-18 07:50发布

问题:

How to pass data/parameter values from one activity to another in android?

I have used

loginname=txtloginname.getText().toString();
password=txtpassword.getText().toString();
Bundle bundle = new Bundle();
bundle.putString("loginname", loginname);
bundle.putString("password", password);
Intent newIntent=new Intent();
newIntent.putExtras(bundle);
setResult(RESULT_OK,newIntent);
finish();

But I can only get loginname value How to put both login and password key and value?

回答1:

You can just say newIntent.putExtra("name",value); use it multiple times to add multiple data. And depending on the data you stored call getStringExtra("name"); in the next activity.



回答2:

You can use the method:

getStringExtra()