Android: onActivityResult() is not calling

烈酒焚心 提交于 2019-12-08 11:24:15

问题


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..


回答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.




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



回答3:


Use below code I hope it will work.

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


来源:https://stackoverflow.com/questions/5540744/android-onactivityresult-is-not-calling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!