So this is the code that I use to transfer the value of a string variable to another activity.
Intent requestLink = new Intent(Search.this, Results.class);
requestLink.putExtra("Link", sendLink);
startActivity(requestLink);
But what if I wish to transfer more than one variable.
Intent requestLink = new Intent(Search.this, Results.class);
requestLink.putExtra("Link", sendLink);
startActivity(requestLink);
Intent userSearch = new Intent(Search.this, Results.class);
userSearch.putExtra("Search", addressInput);
startActivity(userSearch);
Using the code twice will like the above will only just start two separate activities. So, how can I transfer the values simultaneously?
I'm still pretty new to Android development and also OOP.
You can add more than call putExtra more than once for the same intent:
Intent requestLink = new Intent(Search.this, Results.class);
requestLink.putExtra("Link", sendLink);
requestLink .putExtra("Search", addressInput);
startActivity(requestLink);
btnlogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(getBaseContext(),db.class);
String username=uname.getText().toString();
String upaswrd=pass.getText().toString();
// Bundle bundle=new Bundle();
intent.putExtra(name,username);
intent.putExtra(paswrd, upaswrd);
startActivity(intent);
}
});
/** Db.class */
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.db);
Intent intent=getIntent();
String uname=intent.getStringExtra(Gmail.name);
String upass=intent.getStringExtra(Gmail.paswrd);
username=(TextView)findViewById(R.id.u);
username.setText(uname);
pass=(TextView)findViewById(R.id.p);
pass.setText(upass);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With