本文整理汇总了Java中android.app.Fragment.getParentFragment方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.getParentFragment方法的具体用法?Java Fragment.getParentFragment怎么用?Java Fragment.getParentFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Fragment
的用法示例。
在下文中一共展示了Fragment.getParentFragment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isDescendant
import android.app.Fragment; //导入方法依赖的package包/类
/**
* Returns true if the fragment is a descendant of our parent.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private boolean isDescendant(Fragment fragment) {
Fragment root = this.getParentFragment();
while (fragment.getParentFragment() != null) {
if (fragment.getParentFragment() == root) {
return true;
}
fragment = fragment.getParentFragment();
}
return false;
}
示例2: onDestroy
import android.app.Fragment; //导入方法依赖的package包/类
@Override
public void onDestroy() {
super.onDestroy();
//We leave the screen and respectively all fragments will be destroyed
if (getActivity().isFinishing()) {
getMvpDelegate().onDestroy();
return;
}
// When we rotate device isRemoving() return true for fragment placed in backstack
// http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving
if (mIsStateSaved) {
mIsStateSaved = false;
return;
}
// See https://github.com/Arello-Mobile/Moxy/issues/24
boolean anyParentIsRemoving = false;
if (Build.VERSION.SDK_INT >= 17) {
Fragment parent = getParentFragment();
while (!anyParentIsRemoving && parent != null) {
anyParentIsRemoving = parent.isRemoving();
parent = parent.getParentFragment();
}
}
if (isRemoving() || anyParentIsRemoving) {
getMvpDelegate().onDestroy();
}
}