I have two activities.
First calls second like this:
Intent intent = new Intent(this, Second.class);
startActivityForResult(intent, 1);
returning data in second one:
Intent intent = new Intent();
intent.putExtra("a", "la-la-la");
setResult(RESULT_OK, intent);
finish();
and trying to receive this data in first activity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((resultCode == Activity.RESULT_OK) && (currentTask != null)) {
//Here is empty intent extas!!!
Log.d("OrderActivity", "RESULT!!");
}
}
So, request code and response code returned, but intent extra is empty..??
First: Put extra data to intent and start activity [source.java]
ReplyDeleteIntent IntentViewer = new Intent(source.this, destination.class);
IntentViewer.putExtra("first", "first data");
IntentViewer.putExtra("second", "second data");
IntentViewer.putExtra("last", "last data");
startActivity(IntentViewer);
Second: Read the extra data from intent [destination.java]
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
vGetIntentData(intent);
}
private void vGetIntentData(Intent intent){
if (intent.hasExtra("first")){
sFirstString= intent.getStringExtra("first");
}
if(intent.hasExtra("second")){
sSecondString = intent.getStringExtra("second");
}
if(intent.hasExtra("last")){
sLastString = intent.getStringExtra("last");
}
}
Hope this helpful.