https://kotlinlang.org logo
#android
Title
# android
p

pike

09/05/2017, 7:38 AM
How can I pass data from an alarm(broadcast receiver) to the ui? I'm looking at view models and live data, but I'm not sure how to update the viewmodel
stackoverflow 5
I've been searching for about 3 hrs so far, read so much stuff, but can 't figure out how to just have my broadcast receiver update the viewmodel
d

dave08

09/06/2017, 2:20 AM
An alarm usually indicates that something needs to be done in certain timing, but the app usually manages what in the receiver or service maybe by saving state in preferences in model layer after receiving each time to know where you are holding. Otherwise, the rest of the info should be drawn from the model layer like in mvp... What are you trying to do?
p

pike

09/06/2017, 10:55 PM
So far, I'm experimenting with a static live data object and a shared prefs listener. I think I'm going to stick with the shared prefs so the data will persist if the app is killed. I have an alarm that runs every 20 minutes, asks a server for status, then requests the server to send it an SMS. a different receiver listens for the SMS and tells the server if it receives it. The UI just needs to know the last event that fired, especially if there's an error, as well as read an sqlite table that contains all the preceding events and statuses.
12 Views