A
A
Alina Mitrokhina2019-12-10 21:11:10
Android
Alina Mitrokhina, 2019-12-10 21:11:10

How to schedule a notification in Android?

I am writing an application that works with SpaceX API. I get Json from the server. It has a launch_date_unix parameter. Here is what is written about him in the docs

launch_date_unix - UTC launch date/time as a UNIX timestamp in seconds

How would you implement the launch notification? Such a scheme comes to my mind.
1. When the phone is turned on, I launch a BroadcastReceiver which responds to the BOOT_COMPLETED action.
2. In the onReceive method, I make an http request to the api. (In the api there is a request like /launches/next that returns information about the next launch)
3. I take launch_date_unix and check it. If the launch is planned today, then I set WorkManager with setInitialDelay(launch_date_unix, TimeUnit.SECONDS). I read from the documentation that WorkManager will start even after the device is rebooted.
From the point of view of an experienced developer, is this a good approach, or can something be done differently? PS AlarmManager I see no reason to use. Interested to hear how you would do it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sashulya, 2019-12-13
@Shikato

For a good web application, raise one that would find out the launch date once an hour (more often / less often) and, if successful, would send a notification about this to the application through the cloud server, I would also implement a field that, after opening the application, would give out information on this a request to the api (so as not to oversleep the launch for sure)).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question