1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 package androidx.fragment.app; 19 20 import android.os.Parcelable; 21 22 import androidx.lifecycle.ViewModelStore; 23 24 import java.util.List; 25 26 /** 27 * FragmentManagerNonConfig stores the retained instance fragments across 28 * activity recreation events. 29 * 30 * <p>Apps should treat objects of this type as opaque, returned by 31 * and passed to the state save and restore process for fragments in 32 * {@link FragmentController#retainNonConfig()} and 33 * {@link FragmentController#restoreAllState(Parcelable, FragmentManagerNonConfig)}.</p> 34 */ 35 public class FragmentManagerNonConfig { 36 private final List<Fragment> mFragments; 37 private final List<FragmentManagerNonConfig> mChildNonConfigs; 38 private final List<ViewModelStore> mViewModelStores; 39 FragmentManagerNonConfig(List<Fragment> fragments, List<FragmentManagerNonConfig> childNonConfigs, List<ViewModelStore> viewModelStores)40 FragmentManagerNonConfig(List<Fragment> fragments, 41 List<FragmentManagerNonConfig> childNonConfigs, 42 List<ViewModelStore> viewModelStores) { 43 mFragments = fragments; 44 mChildNonConfigs = childNonConfigs; 45 mViewModelStores = viewModelStores; 46 } 47 48 /** 49 * @return the retained instance fragments returned by a FragmentManager 50 */ getFragments()51 List<Fragment> getFragments() { 52 return mFragments; 53 } 54 55 /** 56 * @return the FragmentManagerNonConfigs from any applicable fragment's child FragmentManager 57 */ getChildNonConfigs()58 List<FragmentManagerNonConfig> getChildNonConfigs() { 59 return mChildNonConfigs; 60 } 61 62 /** 63 * @return the ViewModelStores for all fragments associated with the FragmentManager 64 */ getViewModelStores()65 List<ViewModelStore> getViewModelStores() { 66 return mViewModelStores; 67 } 68 } 69