I have an activity "SearchActivity" which extends SherlockActivity. In this activity I have an options menu which has a search bar and a "Go" button. The data that is entered in the search bar has to be passed to the previous activity "NavigationActivity" which extends SherlockMapActivity.
This is a part of my code of SearchActivity:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.go:
Intent intent = new Intent();
intent.putExtra("SearchText", enteredText);
setResult(200, intent);
startActivityForResult(intent, 100);
finish();
break;
}
return true;
}
This is the onActivityResult() method in NavigationActivity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("In onActivityResult method");
if(data != null && resultCode == 200 && requestCode == 100) {
String text = data.getStringExtra("SearchText");
System.out.println("The data is: " + text);
Toast.makeText(this, "The text entered in the search bar is: " + text, Toast.LENGTH_LONG).show();
}
}
The problem is that the onActivityResult() method is never getting called in the NavigationActivity. On pressing the "Go" button I'm able to navigate from the SearchActivity to the NavigationActivity but not able to get the get the data in the NavigationActivity. Could you please help me in this aspect?
Thank you.