I am trying to pass a string from one activity to another. I do not seem to be able to get the extra form the intent. Where am I going wrong?
Here is the code
To put the extra into the intent:
public void onClick(View v) {
// TODO Auto-generated method stub
String string = editTextFeild.getText().toString();
Intent i = new Intent("com.com.com.otherclass");
i.putExtra("dat", string);
startActivity(new Intent("com.com.com.otherclass"));
}
To get the data from the intent (in the com.com.com.otherclass) :
Bundle bundle = getIntent().getExtras();
if (bundle != null){
String string = bundle.getString("dat");
textView.setText(string);
}
p.s. These are not the actual names I use in the code 🙂
Thanks in advance 🙂
In your startActivity line, you’re creating a new Intent. Pass it ‘i’ instead.