Is it possible to convert ComponentActivity or Act...
# android
s
Is it possible to convert ComponentActivity or Activity to FragmentActivity in Kotlin & HOW ??
😶 5
g
Why do you need this? ComponentActivity is way to go for all cases
s
There is a use case which requires FragmentActivity or Fragment for initialisation. But in Compose it's giving error if I am directly passing Activity so needs this conversions. Is it possible ??
Need Casting ComponentActivity as Activity or FragmentActivity
g
ComponentActivity is Activity, no need to cast
n
Copy code
private fun getContextFromComponent(): Context? {
        return when (val componentCallbacks = componentCallbacksWeakReference.get()) {
            is Fragment -> {
                componentCallbacks.context
            }
            is FragmentActivity -> componentCallbacks
            else -> null
        }
    }
g
If some API requires FragmentActivity, you just should extend it, it cannot be "casted" somehow
What are you trying to do in this code? What is componentCallvacks?
s
Yes. Agree. But passing Activity as a parameter to my use case which needs Fragment or FragmentActivity as a instance gives me error as this cast can't be succeed
This is the Use case
g
Right, just extend FragmentActivity, not ComponentActivity
😌 1
s
Checking