Java Code Examples for androidx.fragment.app.fragment#isRemoving()

The following examples show how to use androidx.fragment.app.fragment#isRemoving() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentStack.java    From Alligator with MIT License 6 votes vote down vote up
@NonNull
public List<Fragment> getFragments() {
	List<Fragment> result = new ArrayList<>();
	int index = 0;
	while (true) {
		String tag = getFragmentTag(index);
		Fragment fragment = mFragmentManager.findFragmentByTag(tag);
		if (fragment == null) {
			break;
		}

		if (!fragment.isRemoving()) {
			result.add(fragment);
		}
		index++;
	}
	return result;
}
 
Example 2
Source File: FragmentSwitcher.java    From Alligator with MIT License 6 votes vote down vote up
@NonNull
public List<Fragment> getFragments() {
	List<Fragment> result = new ArrayList<>();
	int index = 0;
	while (true) {
		String tag = getFragmentTag(index);
		Fragment fragment = mFragmentManager.findFragmentByTag(tag);
		if (fragment == null) {
			break;
		}

		if (!fragment.isRemoving()) {
			result.add(fragment);
		}
		index++;
	}
	return result;
}
 
Example 3
Source File: ViewModelHelper.java    From AndroidViewModel with Apache License 2.0 6 votes vote down vote up
/**
 * Use in case this model is associated with an {@link androidx.core.app.Fragment}
 * Call from {@link androidx.core.app.Fragment#onDestroy()}
 *
 * @param fragment fragment
 */
public void onDestroy(@NonNull final Fragment fragment) {
    if (mViewModel == null) {
        //no viewmodel for this fragment
        return;
    }
    if (fragment.requireActivity().isFinishing()) {
        removeViewModel(fragment.requireActivity());
    } else if (fragment.isRemoving() && !mOnSaveInstanceCalled) {
        // The fragment can be still in backstack even if isRemoving() is true.
        // We check mOnSaveInstanceCalled - if this was not called then the fragment is totally removed.
        if (BuildConfig.DEBUG) {
            Log.d("mode", "Removing viewmodel - fragment replaced"); //NON-NLS
        }
        removeViewModel(fragment.requireActivity());
    }
    mBinding = null;
}
 
Example 4
Source File: TaskHelper.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
static boolean isFragmentDestroyed(Fragment fragment) {
  return fragment.isRemoving()
      || fragment.getActivity() == null
      || fragment.isDetached()
      || !fragment.isAdded()
      || fragment.getView() == null;
}
 
Example 5
Source File: BaseBottomFragment.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@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;
    Fragment parent = getParentFragment();
    while (!anyParentIsRemoving && parent != null) {
        anyParentIsRemoving = parent.isRemoving();
        parent = parent.getParentFragment();
    }

    if (isRemoving() || anyParentIsRemoving) {
        getMvpDelegate().onDestroy();
    }
}
 
Example 6
Source File: BaseDialogFragment.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@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;
    Fragment parent = getParentFragment();
    while (!anyParentIsRemoving && parent != null) {
        anyParentIsRemoving = parent.isRemoving();
        parent = parent.getParentFragment();
    }

    if (isRemoving() || anyParentIsRemoving) {
        getMvpDelegate().onDestroy();
    }
}
 
Example 7
Source File: BaseFragment.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@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;
    Fragment parent = getParentFragment();
    while (!anyParentIsRemoving && parent != null) {
        anyParentIsRemoving = parent.isRemoving();
        parent = parent.getParentFragment();
    }

    if (isRemoving() || anyParentIsRemoving) {
        getMvpDelegate().onDestroy();
    }
}
 
Example 8
Source File: BaseFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private Fragment getRemovingParent(Fragment fragment) {
  if (fragment == null) return null;
  Fragment parent = fragment.getParentFragment();
  if (parent != null && parent.isRemoving()) return getRemovingParent(parent);
  if (fragment.isRemoving()) return fragment;
  return null;
}