3

I have an Activity that extends ComponentActivity (Activity variant that is used for Compose based Activity Implementation), thus have no access to FragmentManager.

Is there any way to show DialogFragment(implemented with View System) in it ?

class MyActivity : ComponentActivity(){

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
    //how to show DialogFragment here? there is no access to FragmentManager
        ScreenContent()
    }
}
}
Mohammad cs
  • 191
  • 1
  • 10
  • There is a Context available in Compose, but there is no access to FragmentManager(or its newer variant, SupportFragmentManager) – Mohammad cs May 26 '22 at 11:42
  • Does [this](https://stackoverflow.com/a/68423182/3585796) answer your question? Using activity you can get `FragmentManager` – Phil Dukhov May 26 '22 at 13:19
  • no this is not the answer of my question, i want to show fragment with supportFragmentManager – Mohammad cs Nov 12 '22 at 09:22

1 Answers1

2

I reckon, you must use FragmentActivity instead of ComponentActivity. It is already extended from ComponentActivity and supported for fragment manager. I have used it and it worked.

For instance;

class MyActivity : FragmentActivity(){

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
        val dialogFragment = CustomDialogFragment.newInstance() // DialogFragment
        dialogFragment.show(supportFragmentManager, "Your classname")
        ScreenContent()
    }
}
}