开发者

Android: onActivityResult() is not calling

开发者 https://www.devze.com 2023-02-22 12:36 出处:网络
I\'m facing with a problem relatedonActivityResult(). I use TabActivity as a main Activity. Each of the tabs is activityGroup.

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开发者_如何学C-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..


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.


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);
    }


Use below code I hope it will work.

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

精彩评论

暂无评论...
验证码 换一张
取 消