07-31-2023, 09:55 AM
I have an Android GCM based Alarm Clock application that, for our specific industry use case, works great.
**Here’s how it works now:** A back-end system sends a GCM message to the phone. A BroadcastReceiver starts the Alarm Clock Activity which overrides volume settings, plays the alarm, turns on the back light, displays a full screen UI over the lock screen, and communicates (via upstream GCM) to the back-end when the Alarm is dismissed. The phone can be restarted, the app not launched by the user, and the Alarm Clock will still get launched when the back-end pushes the GCM message.
**Programming design question:** What is the correct way to replace this with Firebase?
**Approaches I have tried out:**
- Simply replace GCM with FCM (not using a Firebase Realtime database)
- Start a Service at boot (and within onCreate) that keeps a reference to a Firebase Realtime database. ()
Both of those approaches work. Certainly replacing GCM with FCM is straightforward. Is keeping a Firebase reference alive in a Service the right architecture for processing an Alarm? Doesn’t feel right.
I have not yet coded with `keepSynced(true)`. Perhaps that is what I should be using. I’m looking for a design that uses Firebase data synchronization instead of having to deal with the FCM RemoteMessageBuilder layer directly - I'll be able to retire a lot of XMPP code, a Windows Service, etc..
What’s the correct way to implement my Alarm Clock using Firebase?
**Here’s how it works now:** A back-end system sends a GCM message to the phone. A BroadcastReceiver starts the Alarm Clock Activity which overrides volume settings, plays the alarm, turns on the back light, displays a full screen UI over the lock screen, and communicates (via upstream GCM) to the back-end when the Alarm is dismissed. The phone can be restarted, the app not launched by the user, and the Alarm Clock will still get launched when the back-end pushes the GCM message.
**Programming design question:** What is the correct way to replace this with Firebase?
**Approaches I have tried out:**
- Simply replace GCM with FCM (not using a Firebase Realtime database)
- Start a Service at boot (and within onCreate) that keeps a reference to a Firebase Realtime database. ()
Both of those approaches work. Certainly replacing GCM with FCM is straightforward. Is keeping a Firebase reference alive in a Service the right architecture for processing an Alarm? Doesn’t feel right.
I have not yet coded with `keepSynced(true)`. Perhaps that is what I should be using. I’m looking for a design that uses Firebase data synchronization instead of having to deal with the FCM RemoteMessageBuilder layer directly - I'll be able to retire a lot of XMPP code, a Windows Service, etc..
What’s the correct way to implement my Alarm Clock using Firebase?