I have multiple variables to pass from one activity to another.
I have this in the first activity:
public void onClick(View v) {
switch(v.getId()){
case R.id.bStartGame:
Intent i = new Intent(StartScreen.this, GameScreen.class);
Bundle extras = new Bundle();
extras.putString("Name 0", sName0);
extras.putString("Name 1", sName1);
extras.putString("Name 2", sName2);
.
.
.
i.putExtras(extras);
StartScreen.this.startActivity(i);
finish();
break;
In the second activity, I have this:
Intent i = getIntent();
Bundle extras = i.getExtras();
String name0 = extras.getString("Name 0");
TextView test = (TextView) findViewById(R.id.tvTEST);
test.setText(name0);
However, the textview shows nothing when I do this. How can I fix this?
EDIT: In the first activity I have:
name0 = (EditText) findViewById(R.id.etName0);
sName0 = name0.getText().toString();
and the same for all the other names with their relevant references.
Also, just for clarification, name0 is the edittext, sName0 is the string and “Name 0” is the key.
Nothing is wrong in the code you’ve shown.
name0here has the correct value:"". If it was not sending the extras properly, it would benull, and would give you aNullPointerExceptionon.setText().Here, you’re overwriting
"Name 1"with the value ofsName1, which is probably blank. I’d assume that you want to sendsName0instead.