Hi all. I have been looking for a good Compose bes...
# compose
b
Hi all. I have been looking for a good Compose best practice way of triggering local Notifications, but can't seem to find any Compose specific ways of achieving this (in a UI + ViewModel architecture way). I keep finding "Helper Class" or "Accompanist" suggestions, and the Google Android recommendation is not helpful in this regard either. Anyone know of Compose ways of triggering and managing Notifications?
c
You might not find anything because you are looking in the wrong context. Compose is an UI framework that has nothing to do with triggering Notifications.
1
Notifications are usually triggerd by a background service service.
b
Respectfully, Compose offers a lot of functionality that is not strictly UI, like launching system activities, accessing hierarchy logic, coroutine handling, etc, so suggesting that UI related Notifications management could be functionality either provided or at least considered does not seem like outside the scope of reality. But if that does not exist, it does not exist. That's ok. Thank you @Chrimaeon for the input.
c
What I meant is that Compose is used for when the app is open and the user is looking at it. Notifications on the other hand are used when the user is not having your app open to tigger him using it. Thats why you’ll need some kind of service that is running in the background and triggers a notification because of an event happening somewhere.
👍🏼 1
j
Just wanted to add, activities are definitely an extensions of UI. Furthermore, due to system limitations (aka requiring Context) the most logical place to launch them is inside of your UI (Compose) since it’s an anti-pattern to pass context inside of a ViewModel. The system has limitations around launching activities while the app is in a background service. You should use a pending intent for such a thing. Further, you UI shouldn’t being doing “coroutine handling” or much of it besides using a CoroutineScope, (whether from a
LaunchedEffect
or a
remembered
scope) to call a suspending function. I’m not sure what you mean by “hierarchy logic” but on the surface it seems related to UI… Notifications should not be intertwined with your UI beside calling a function in your ViewModel or an independent service.
b
Just so that we are clear on what is happening here, you both are explaining things under the assumption that others don't know these things, and we all know *ass*umptions make *ass*es out of you. So while I appreciate answers to questions I did not ask, and explanations even ChatGPT and Gemini could come up with, let's try to stick to the original question, for which the answer is No. 👍🏼
j
And we are explaining reasoning behind why there isn’t a “Compose ways of triggering and managing Notifications?
b
A question no one asked. 😉
j
What is wrong with you? You come here asking for help, people are kindly informing you that what you are trying to achieve isn’t recommended and you get defensive. You could have just as easily responded with kindness and left the snark at home.
b
Nothing wrong here and not defensive. In the same way you felt it was necessary to "explain" something no one asked, under the assumption that the other person doesn't know what you know, I am explaining that it is not the correct approach to answer a very specific question with answers under the assumption that the question is being asked because the other person doesn't know the plethora of other approaches, all of which were not asked about. See how we both "explained things", but I'm wrong and you're right? I'm sure you see that. But thank you for the input.