Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending multiple variable values to another activity

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.

like image 877
Min Avatar asked Oct 19 '25 14:10

Min


2 Answers

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);
like image 122
Philip Sheard Avatar answered Oct 22 '25 04:10

Philip Sheard


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);

}
like image 43
emraan tamboli Avatar answered Oct 22 '25 03:10

emraan tamboli