'Android: onActivityResult() is not calling

I'm facing with a problem related onActivityResult().

I use TabActivity as a main Activity. Each of the tabs is activityGroup.

A ActivityGroup's sub-activity A(Activity) sends the intent to B(Activity) using

startActivityForResult( , ) .

But when B Activity finish, onActivityResult() is not called in A.

A Activity

Intent intent = new Intent(A.this, B.class);
startActivityForResult(intent, 1);

B Activity

Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();

What is wrong?

Because of TabActivity, ActivityGroup or Flag??

Please advice..



Solution 1:[1]

The problem with ActivityGroup inside TabActivity. I suppose finishFromChild will be invoked in parent activity (in TabHost). Check it.

Actually ... Do u really need ActivityGroup inside TabActivity?! Avoid it, e.g. use simple TabHost view in every tab of your parent TabActivity, this way TabActivity will switch views, not activities.

Solution 2:[2]

Try to call the startActivityForResult using the context of the tabgroup activity containing your current activity and then listen in the tabgroup activity.

Use this to get the tabGroupActivity:

TabGroupActivity parentActivity = (TabGroupActivity)getParent();

And then call startActivityForResult from it:

parentActivity.startActivityForResult(...);

Finally , put an onActivityResult listener in the tabGroupActivity:

protected void onActivityResult(int requestCode, int resultCode,Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
    }

Solution 3:[3]

Use below code I hope it will work.

 Intent intent = new Intent(getParent(), B.class);
    startActivityForResult(intent, 1); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Zar E Ahmer
Solution 3 Bhaskar Reddy