onActivityResult not wait results

I have this code:

in class MainActivity when SettingButton is pressed:

static final int DUMP_REQUEST = 1;

public void onSettingButtonClick(View button)
{
    //call options menu activity
    Intent intent = new Intent(MainActivity.this, OptionsMenuActivity.class);
    startActivityForResult(intent, DUMP_REQUEST);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == DUMP_REQUEST)
    {
        if (resultCode == RESULT_OK)
        {
            Log.e("onActivityResult", "resultOK");
        }
        else
        {
            Log.e("onActivityResult", "result_not_Ok");
        }
    }
}

in class OptionsMenuActivity when SaveButton is pressed:

public void onSaveButtonClicked(View v)
{
    String dumpDb="true";
    Intent intent = new Intent();
    intent.putExtra("DUMP", dumpDb);

    setResult(RESULT_OK, intent);
    finish();
}

When I press SettingButton, OptionsMenuActivity starts, and immediately appears the Log:

E/onActivityResult´╣Ľ result_not_Ok

When I click the SaveButton, OptionsMenuActivity is closed and MainActivity runs.

/--/

My problem is that onActivityResult() not waits for the result until I press SaveButton, and never resultCode == RESULT_OK, so never I can do my stuff depending on OptionsMenuActivity state

Answers


Maybe your OptionsMenuActivity has in manifest launchmode equal to singletask? This is an excerpt from startActivityForResults doc:

For example, if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result.


Need Your Help

Shopify Liquid How do I use for-loop index variables in an assign or capture tag?

for-loop interpolation shopify liquid

I am just getting into some liquid template coding on a Shopify site. How do I use the for-loop index/variable when defining variable names in assign or capture tags? ie: I'm trying to condense the...

Interpretation of int (*a)[3]

c++ c arrays pointers types

When working with arrays and pointers in C, one quickly discovers that they are by no means equivalent although it might seem so at a first glance. I know about the differences in L-values and R-va...