I have this code :
Button groupsButton = (Button)findViewById(R.id.groupsButton);
groupsButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent myintentGroups=new Intent(CreateMessageActivity.this, GroupsActivity.class).putExtra("<StringName>", "Value");
startActivityForResult(myintentGroups, 3);
}
});
and now I want to write the onActivityResult, I tried adding this code inside the onClick but it’s not working (Eclipse gives me an error):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
String result_string=data.getStringExtra("<StringName>");
}
Is the code for writing onActivityResult wrong or maybe I’m putting it in the wrong place ?
** Edit : ** the code :
Button groupsButton = (Button)findViewById(R.id.groupsButton);
groupsButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent myintentGroups=new Intent(CreateMessageActivity.this, GroupsActivity.class).putExtra("<Came From Create Message>", "Value");
startActivityForResult(myintentGroups, 3);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
String result_string=data.getStringExtra("<StringName>");
}
Edit 2: The errors:
Multiple markers at this line
– Syntax error on token “(“, ; expected
– void is an invalid type for the variable
onActivityResult
– Syntax error on token “)”, ; expected
– Syntax error on token “,”, ; expected
– Syntax error on token “,”, ; expected
onActivityResult should be placed in the Activity class that contains the onClick not in the actual onClick. The CreateMessageActivity.this in the new Intent will indicate which activity the result should be returned to.