Android 使用 getFragmentManager() 还是 getSupportFragmentManager()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25306197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using getFragmentManager() vs getSupportFragmentManager()?
提问by COBOL
When should I use getFragmentManager() when showing DialogFragments, and when should I use getSupportFragmentManager()?
显示 DialogFragments 时应该什么时候使用 getFragmentManager(),什么时候应该使用 getSupportFragmentManager()?
Currently, I am showing my DialogFragments as follows:
目前,我显示我的 DialogFragments 如下:
myDialogFragment.show(getFragmentManager(), "My Dialog Fragment");
回答by Itzik Samara
If you are using API >= 14, then use getFragmentManager()
and while using Support Package you have to use getSupportFragmentManager()
如果您使用 API >= 14,则使用getFragmentManager()
并且在使用支持包时您必须使用getSupportFragmentManager()
For Example Android Support Package v4 or v13.
例如 Android 支持包 v4 或 v13。
回答by Chintan Shah
When you are using android.support.v4.app.FragmentManager
then you should use getSupportFragmentManager()
and if you are using android.app.FragmentManager
then use getFragmentManager()
.
当您使用时,android.support.v4.app.FragmentManager
您应该使用getSupportFragmentManager()
,如果您使用,android.app.FragmentManager
则使用getFragmentManager()
.