问题
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