-4

I am working on this code, and get an error, the variable "textoviejo" is returned as null, I would like to know what is wrong here. Thank you

Activity 1

EditText input = (EditText) findViewById(R.id.input); 
startActivityForResult(new Intent(this, Activity2.class), REQUEST_CODE_SEND);
Intent i = new Intent(this, EmoticonActivity.class);   
i.putExtra("textoviejo", input.getText().toString()); 

Activity 2

 Intent intent = new Intent();


    String mensaje = intent.getStringExtra("textoviejo");
    String emoticon = mensaje + ":)";
    intent.putExtra(Extra.EMOTICON, emoticon);
    setResult(RESULT_OK, intent);
    finish();

Result in EditText = null

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28
JackFlash
  • 11
  • 3

3 Answers3

1

instead of

Intent intent = new Intent();

try

Intent intent = getIntent();
Sam
  • 4,046
  • 8
  • 31
  • 47
0

you didnt used

   Intent intent = getIntent();

and than call

  String mensaje = intent.getStringExtra("textoviejo");
Dhwanik Gandhi
  • 685
  • 6
  • 12
0

is EmoticonActivity.class is your activity2 ? if yes then

you are doing it wrong, do it like this

Activity 1

EditText input = (EditText) findViewById(R.id.input); 
Intent i = new Intent(this, EmoticonActivity.class);   
i.putExtra("textoviejo", input.getText().toString()); 
startActivityForResult(i, REQUEST_CODE_SEND);
jaimin
  • 563
  • 8
  • 25