0

I've made an intent and i've put inside 2 extras

Intent intent = new Intent(MainActivity.this, Options.class);
                TextView labelName = (TextView) findViewById(R.id.label1); // value = "Counter1"
                TextView label2Name = (TextView) findViewById(R.id.label2); // value = "Counter 2"
                String lblNameDefault = labelName.getText().toString();
                String lbl2NameDefault = label2Name.getText().toString();
                intent.putExtra(LABEL_NAME_DEFAULT, lblNameDefault);
                intent.putExtra(LABEL_2_NAME_DEFAULT, lbl2NameDefault);

In my other activity i retrieve the info from them like this

//Get name from the label
    Intent intent = getIntent();
    String lblNameDefault = intent.getStringExtra(MainActivity.LABEL_NAME_DEFAULT);
    String lbl2NameDefault = intent.getStringExtra(MainActivity.LABEL_2_NAME_DEFAULT);



   //Set current name to editText
    EditText labelNameDefault = (EditText)findViewById(R.id.set_name);
    EditText label2NameDefault = (EditText)findViewById(R.id.set_name2);
    labelNameDefault.setText(lblNameDefault, TextView.BufferType.EDITABLE);
    label2NameDefault.setText(lbl2NameDefault, TextView.BufferType.EDITABLE);

The problem is that i receive to both labelNameDefault and label2NameDefault the result from LABEL_2_NAME_DEFAULT.

Can i only pass one extra? How can i pass them both?

By default the value of labelName is "Counter 1" and the value of label2Name is "counter 2"

If i comment out intent.putExtra(LABEL_2_NAME_DEFAULT, lbl2NameDefault); the first label name is ok. It looks like LABEL_2_NAME_DEFAULT is overwriting LABEL_NAME_DEFAULT

DoubleP90
  • 1,249
  • 1
  • 16
  • 29
  • My guess is you are adding same value for both extras. Post some extra code if possible. – kosa Aug 04 '12 at 00:06
  • I think @thinksteep is on the right track; also, what are the values of `LABEL_NAME_DEFAULT` and `LABEL_2_NAME_DEFAULT`? – Cat Aug 04 '12 at 00:06

3 Answers3

1

You could pass a 'bundle' of extras rather than individual extras if you like, for example:-

Intent intent = new Intent(this, MyActivity.class);
Bundle extras = new Bundle();
extras.putString("LABEL_NAME_DEFAULT",lblNameDefault);
extras.putString("LABEL_2_NAME_DEFAULT",lbl2NameDefault);
intent.putExtras(extras);
startActivity(intent);
Then in your Activity that your triggering, you can reference these like so:-

Intent intent = getIntent();
Bundle extras = intent.getExtras();
String username_string = extras.getString("LABEL_NAME_DEFAULT");
String password_string = extras.getString("LABEL_2_NAME_DEFAULT");
Or (if you prefer):-

Bundle extras = getIntent().getExtras();
String username_string = extras.getString("LABEL_NAME_DEFAULT");
String password_string = extras.getString("LABEL_2_NAME_DEFAULT");

Hope this helps! :-)
Furqi
  • 2,403
  • 1
  • 26
  • 32
0

You can pass two (or more) extras in an intent. You need to make sure that LABEL_2_NAME_DEFAULT and LABEL_NAME_DEFAULT does not have the same value, though.

MByD
  • 135,866
  • 28
  • 264
  • 277
0

activity one

Intent intent = new Intent(MainActivity.this, Options.class);
            TextView labelName = (TextView) findViewById(R.id.label1); // value = "Counter1"
            TextView label2Name = (TextView) findViewById(R.id.label2); // value = "Counter 2"
            String lblNameDefault = labelName.getText().toString();
            String lbl2NameDefault = label2Name.getText().toString();
            intent.putExtra("LABEL_NAME_DEFAULT", lblNameDefault);
            intent.putExtra("LABEL_2_NAME_DEFAULT", lbl2NameDefault);

activity two

 username_string = getIntent().getExtras().getString("LABEL_NAME_DEFAULT");
 password_string = getIntent().getExtras().getString("LABEL_2_NAME_DEFAULT");
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98