Is it possible to use Compose without an AppCompat...
# compose
j
Is it possible to use Compose without an AppCompatActivity, and just
android.app.Activity
? I see that it requires a
ViewTreeLifecycleOwner
, which can be instantiated and set manually. However the
ViewTreeSavedStateRegistryOwner
cannot be instantiated, so it must be used with an AppCompatActivity, right? Is there any way for me to get a
ViewTreeSavedStateRegistryOwner
without AppCompatActivity or get Compose (specifically
ComposeView
, which checks for these) to work?
l
You want to use
androidx.activity.ComponentActivity
1
j
Yeah true, but is there a way to do it without it
g
Why don't you want to use ComponentActivity ?
j
The scenario I want to use it for just 100% requires an Android Activity
m
However the 
ViewTreeSavedStateRegistryOwner
 cannot be instantiated, so it must be used with an AppCompatActivity, right?
AppCompatActivity
comes from a library. Anything that a library author can write, we can write. We have examples of using Compose in an
InputMethodService
(https://stackoverflow.com/a/65760080/115145) and from a service showing a system overlay (https://gist.github.com/handstandsam/6ecff2f39da72c0b38c07aa80bbb5a2f). AFAIK, both copied code out of
ComponentActivity
and adjusted it to suit their needs.
g
From what people have said in other similar thread if you're doing a pure compose app you can just use ComponentActivity, no need for AppCompat
j
Thanks, I was missing that how the SavedStateRegistryController is instantiated and used. I thought it would need an instance that already has implemented the
getSavedStateRegistry()
. I will try it
g
👍
j
I cannot use anything else then
android.app.Activity
. It is a pretty special use case, i know. And don't try to convince me that I'm doing it wrong, I know that and there is no other way lol
g
Haha I wont :D
129 Views