1

I have a DataActivity which has to ask the user to fill out a form and then return the data to MainActivity

DataActivity is called from MainActivity like this :

Intent i = new Intent();
i.setClass(this, DataActivity.class);
startActivityForResult(i,RESULT_OK);

DataActivity should return data intent to MainActivity like this :

Intent i = new Intent();
i.putExtra("funcX", ((EditText)findViewById(R.id.data_eq_x)).getText().toString());
i.putExtra("funcY", ((EditText)findViewById(R.id.data_eq_y)).getText().toString());
i.putExtra("constants", (Serializable)constants);
setResult(RESULT_OK,i);
finish();

but onActivityResult is never called in MainActivity after this... Whenever i try to access funcX or funcY in MainActivity, I get NullPointerexception.

NOTE: constants variable can be and in fact was null when i was testing this code.

I'm developing on Android 2.2 on the emulator.

udiboy1209
  • 1,472
  • 1
  • 15
  • 33

1 Answers1

2

Read the documentation for the parameter requestCode on startActivityForResult

requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits.

RESULT_OK is equal to -1..

Change your request code to some positive value for it to work

Intent i = new Intent(this, DataActivity.class);
startActivityForResult(i,345);
dymmeh
  • 22,247
  • 5
  • 53
  • 60