Trying to add a ComposeView into a Window service ...
# compose
a
Trying to add a ComposeView into a Window service for a Foreground Service. The view asks for LifecycleOwner and SavedStateRegistryOwner, and I’m having trouble making it work. Any idea on this? I’m basically trying to draw a ComposeView on top of other apps.
I’m getting this error:
Copy code
java.lang.IllegalStateException: You can consumeRestoredStateForKey only after super.onCreate of corresponding component
        at androidx.savedstate.SavedStateRegistry.consumeRestoredStateForKey(SavedStateRegistry.java:77)
m
See https://gist.github.com/handstandsam/6ecff2f39da72c0b38c07aa80bbb5a2f (as seen in https://jetc.dev/issues/049.html) for an example of a system overlay using Compose UI
😍 1
a
Omg youre CommonsWare. Thanks! I'll try it out.
m
I can't take the credit for the gist -- that was @handstandsam! I'm just an implementation of a message bus. 😁
a
It worked! thank you so much
m
The Box is taking all the touches however so I can’t touch the view behind it
I don't think that is a Compose issue. Do you have a sample app working outside of Compose that is doing what you want?
ComposeView is final so I can’t override 
dispatchTouchEvent
 to ignore touches
AFAIK, that has not been relevant since Android 4.0. AFAIK, you need to look at window flags to provide to the window, such as
FLAG_NOT_TOUCHABLE
or perhaps
FLAG_NOT_TOUCH_MODAL
. And, this is not tied to Compose. I recommend that you get a sample working first without Compose UI, then (and only then) adapt it to Compose.
a
Yep. I’ve been trying those flags,
FLAG_NOT_TOUCHABLE
won’t let me touch my overlay button.
FLAG_NOT_TOUCH_MODAL
is the closest that could work but I cannot move around my compose button without having a fillMaxSize() parent where it could move around. You’re right, I should try to make this work without compose… There’s a bunch of apps that were able to achieve this though (without using the new Bubble API)
h
Glad it worked! 🙂
a
So you were right @commonsware . The window is taking all the input, basically. The bubble implementations I saw wrap the window into the small button and reposition the window itself so it doesn't block stuff behind it. I didn't find a way to modify the window within compose as it's within a ComposeView, so I guess I'd need to handle touch and positioning the old way in this case...
👍🏻 1