getStringExtra returns null value

1.5k views Asked by At

I have a problem which is that the getStringExtra keeps return a null value. Why is that?

This is where the string is added:

EditText num = (EditText) findViewById(R.id.editText6);
String tnum = num.getText().toString();
Intent i = new Intent(this,ConfirmOrder.class);
i.putExtra("tablenum",tnum);

And this the part the string is extracted:

Intent i = getIntent();
String num = i.getStringExtra("tablenum");
2

There are 2 answers

0
Paraneetharan Saravanaperumal On

make sure tnum varaible is not null, try this:

Intent i = getIntent();
String num = i.getExtras().getStringExtra("tablenum");

or

Bundle ePzl= new Bundle();
ePzl.putString("tablenum", tnum);
Intent i = new Intent(this,ConfirmOrder.class);
i.putExtras(ePzl);

and

Intent i = getIntent();
String num = i.getExtras().getStringExtra("tablenum");
0
Safwan Hijazi On

put like this:

Intent intent = new Intent(this, ConfirmOrder.class);
intent.putExtra("tablenum", tnum);

receive like this:

Bundle extras = getActivity().getIntent().getExtras();
String value = extras.getString("tablenum");