Skip to content Skip to sidebar Skip to footer

Activity Started With Startactivityforresult() Not Returning To Calling Activity

I have 3 Activities - A, B, and C. In a nutshell, Activity A starts Activity B, then A also starts Activity C and expects a result from C, but never gets it. Here is the applicati

Solution 1:

I was never able to get this to work, so I ended up using a Handler instead to return the data to the necessary Activity.

UPDATE: After running into this again, I found out that the real reason this wasn't working is because I had android:noHistory="true" for the calling/receiving Activity A in the manifest. Removing android:noHistory="true" fixed it, but if you need it to be true, then Handlers are a good workaround.

Solution 2:

I don't think you should use getApplicationContext() in the intent.

From the developer website.

getApplicationContext()
Return the context of the single, global Application objectof the current process.

When you you startActivityForResult() it tries to return to the activity specified in the intent, which you are providing as the global application context.

If you have an ActivityB then you should call it like

Intent intent = newIntent(ActivityB.this, ActivityC.class);
startActivityForResult(intent, 0);

Then it will try to return to ActivityB when ActivityC is done.

Solution 3:

You might give this a try:

if (getParent() == null) {
setResult(RESULT_OK, dataTobePassback);
} else {
getParent().setResult(RESULT_OK, dataTobePassback);
}

dataTobePassback is an Intent that carries the stuff you may need to pass back to the calling activity

Post a Comment for "Activity Started With Startactivityforresult() Not Returning To Calling Activity"