I am facing an issue in my Android app where I'm unable to use supportFragmentManager in my ComponentActivity subclass. As per my understanding, ComponentActivity does not support the FragmentManager out of the box. And if I want to use supportFragmentManager Activity should be subclasses of AppCompatActivity or FragmentActivity. However, I'm encountering a problem where it seems to be unavailable. I want to use both JetPack Compose and XML in my class,
I have followed this https://stackoverflow.com/a/65653754/3467187
class AbcActivity : ComponentActivity(n) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_permissio)
if (savedInstanceState == null) {
// Here I want to use supposrtFragmentManger
}
}
}
Gradle file look like this,
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.8.0")
..
}
Any idea to use both JetPack Compose and XML in same class in a way I could use fragment Manager?
Yes, you can use Compose in your XMLs and also the other way around.
From this answer.
Method 1
1. Add
ComposeViewto you XML2. Set the content from you activity
Method 2
You can use
AndroidViewBinding.Before jumping on with this method, read this
XML in Compose