我有HomeActivity
在viewpager中包含许多片段。现在我有2个片段
AddBalanceFragment
AddSubscriptionFragment
我从两个片段调用onActivityResult
,两者都有相同的代码。 onActivityResult首先转到HomeActivity的onActivityResult
正常工作AddBalanceFragment
它会转到addBalanceFragment的onActivityResult
,但当我尝试与AddSubscriptionFragment
相同时
它也适用于AddBalanceFragment的onActivityResult
//nestedfragments contains 4 fragments 3rd is addBalanceFragment and 4th AddsubsprtionFragment
// HomeActivity.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e(TAG, "onActivityResult");
// notifying nested fragments (support library bug fix)
final FragmentManager childFragmentManager = getSupportFragmentManager();
if (childFragmentManager != null) {
final List<Fragment> nestedFragments = childFragmentManager.getFragments();
if (nestedFragments == null || nestedFragments.size() == 0) return;
for (Fragment childFragment : nestedFragments) {
if (childFragment != null && !childFragment.isDetached() && !childFragment.isRemoving()) {
childFragment.onActivityResult(requestCode, resultCode, data);
}
}
}
}
AddBalanceFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
if (resultCode == -1) {
}
}
AddSubscriptionFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
if (resultCode == -1) {
}
}
答案 0 :(得分:1)
我用静态变量状态得到它:)
toggleClass("show");
答案 1 :(得分:0)
你能确定你在打电话吗
super.onActivityResult(requestCode, resultCode, data);
on fragment的onActivityResult方法。
您甚至不需要在活动中手动调用这些方法