Hello everyone if you would kindly help me. I'm stuck on how to retrieve the bundle data from another activity. Basically I have two activities which is that when I pressed a button on the first activity, it will go on the second activity and then sets the string values which is later on to be passed on the first activity. What I did was I used the bundle to put the string values. My question is that how can I get the bundle values (of strings) from the second activity and return it on to the first activity? Here is my code:
FirstActivity (going on to second activity):
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(this,
SecondActivity.class), REQUEST_CODE_SAMPLE);
}
});
SecondActivity: (returning the bundle value)
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Bundle b = new Bundle();
bundle.putString("A", "Aloha");
bundle.putString("B", "Bubbles");
setResult(
Activity.RESULT_OK,
getIntent().putExtras(b));
}
});
}
FirstActivity (going to retrieve the bundle values):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_SAMPLE:
if (resultCode == RESULT_OK) {
bundle = getIntent().getExtras();
//WHAT TO DO TO GET THE BUNDLE VALUES//
String a = //STORE FIRST VALUE OF BUNDLE
String b = //STORE SECOND VALUE OF BUNDLE
}
break;
default:
break;
}
}