Question

I'm creating an intent in an activity A and then starting up an activity B with startActivityForResult from the setOnItemClickListener of a ListView in Android.

Intent detailsIntent = new Intent(MyTeamDetailsActivity.this, MatchMediaActivity.class);
                                        detailsIntent.putExtra("data", data);
                                        detailsIntent.putExtra("hasSmoovz",mSmoovz);
                                        detailsIntent.putExtra("uitslagen", true);
                                        startActivityForResult(detailsIntent, MATCH_MEDIA_REQUEST);

The problem is that when launching the activity, it immediately enters in the onActivityResult part of the activity A, but with a resultCode = 0; then, after doing it, it then loads the onCreate, etc. of the activity B.

The following code is my onActivityResult:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == MATCH_MEDIA_REQUEST) {
            if (resultCode == RESULT_OK) {
                refreshData();
            }
        }
    }

And this is the simple code where I finish the activity B and give it a result code:

@Override
    public void onBackPressed() {
        setResult(RESULT_OK);
        finish();
    }

Any idea why this could be happening? I've never seen this before. Thanks a lot in advance.

Was it helpful?

Solution

It's because I had my activity in the manifest as singleTask: https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

(thanks to @SteveBarret)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top