When you have a primary constructor, the secondary constructors cannot call super constructors. They have to call the primary constructor.
A Fragment's primary constructor should always be empty, because the framework can destroy and recreate it, and it recreates it by calling the empty constructor. Therefore, your FragmentAllCategories code would not be able to rely on the categories
collection having the items you first passed to it. So if you instantiate your Fragment with some Categories and start it, if the screen rotates or the app goes to the background and comes back, those ModelCategories will be gone.
To avoid this problem, you can put the categories
collection in an Activity-scoped ViewModel, which will survive screen rotations and app-backgrounding. Or you can make your ModelCategory a Parcelable and add it to the Fragment's bundle before you first start it. The bundle will automatically be restored when the Fragment is recreated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…