Anyone know how to put together a “global listener...
# android
t
Anyone know how to put together a “global listener” for android? I’m using awsIot to listen for device to device communication. When I receive a message, I want this message to be listened for all screens of the app, and then navigate to a specific screen. So, how can I use awsIotClient globally?
not kotlin but kotlin colored 2
f
not kotlin but kotlin colored But, let me give you a pointer; Sounds like what you need is an Event Bus. Using an Event Bus, you can listen (or subscribe) to a single source, from multiple locations in your app. https://square.github.io/otto/ https://dev.to/mohitrajput987/event-bus-pattern-in-android-using-kotlin-flows-la In your case; You can make a Bus (singleton) in you Application, and then subscribe in every of your screens (in onCreate). (don’t forget to unsubscribe in the onDestroy) When the AwsIotClient fires, publish this fact onto the Bus, and all the subscribers (screens) will know it happend, and can respond accordingly. The specifics will depend on your own implementation. Hope this helps! Good luck!
t
I really appreciate the suggestion Frank. Since I’m using compose, do you know if the same subscription is possible for compose screens? My navigation is also based on compose
f
I’m not familiar enough with Compose to answer; But I would assume you should be able to do it!
t
Are you at all familiar with device/app locking? The idea is that a device/app is registered and able to use the app. The app can become unregistered at any moment. At that moment, the app should pop to the registration screen, no matter where the user is currently. How can I make this dynamic lock screen?
f
You could have a login-activity, and a main-activity (with all your compose screens); The main-activity could listen to the eventbus, and when triggered, start the login-activity + finish itself.
t
2 activities is just bad design. And it needs to be global authentication. User needs to get the authentication screen in all areas of the app if I disable a specific device authentication
o
You should use shared flow, that will solve all your problems.