I am using a simple function OnActivityResult, but it is not returning me desired results.
Please see my code and tell me where i am doing wrong.
public void OnClickFunction(View view)
{
Intent intent = new Intent(getApplicationContext(), Second.class);
startActivityForResult(intent, RESULT_OK);
/// My actions. . .
}
Then in the Second class, i have set Result like this:
Button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
ValueOne = EditText.getText().toString().trim();
if (ValueOne.equals(String.valueOf(Answer)))
{
Toast.makeText(getApplicationContext(), "Correct Answer", 0).show();
Second.this.setResult(RESULT_OK, null);
Second.this.finish();
}
else
{
Toast.makeText(getApplicationContext(), "Wrong Answer", 0).show();
}
}
});
Now coming back to the first.class, from where the Intent was called:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// if (requestCode == RESULT_OK)
// {
if (resultCode == RESULT_OK)
{
///// MyActions. . .
}
// }
}
The debugger is not debugging this function, so the desired results are not coming.
Where i am doing wrong??
You have to destroy the second activity. Try pressing back button. I am able to see all the log messages in onActivityResult
First Activity
SecondActivity