onActivityResult always getting Result_Canceled from TabActivity

Recently while working with tabs, I see this situation onActivityResult , always getting 0(RESULT_CANCELLED).

I have four activities A-Activity,B-TabActivity,C-Activity, D-Activity. where A starts TabActivity B, and in this TabActivity, Im displaying 2 tabs C and D as child activities.

I need result from C or D whether success or not when Activity closed. So I started TabActivity B which displays C and D as tabs.. as shown below,

Intent intent = new Intent(this, TabActivityB.class);

now after getting required information in Activity C, I closed Activity C by setting result as below

Intent data = new Intent();

and when i check the resultCode in Activity A, in

onActivityResult(int requestCode, int resultCode, Intent data)

method, Im always getting


Solution to handle this onActivityResult issue,

In child Activity C and D, before finish we should check the getParent() method null or not… and then setResult accordingly… as shown below,

Intent data = new Intent();
if (getParent() == null) {
setResult(Activity.RESULT_OK, data);
} else {
getParent().setResult(Activity.RESULT_OK, data);

After applying this change, Im able to get the exact resultCode in Activity A.

Hope it helps somebody..

Cheers 🙂

Ref link & credits:http://stackoverflow.com/a/2621390/341443

You may also interested in


Leave a Reply

Your email address will not be published. Required fields are marked *