Good day!

There is a date when the user needs to be reminded of something. It is necessary to remind for 3 days, 3 times a day (in the morning, in the afternoon and in the evening). After the date has passed, another date is generated (in a month). And so on the cycle.

I was able to configure on my own so that when starting the service (Service), a notification (Notifications) was launched, but I still can not think of the cycle so that it does this for 3 days 3 times a day and which tools are better to use?

    1 answer 1

    Service is not needed here.

    You need:

    1. Alarmmanager
    2. Configure it to send a message to the receiver at the right time.
    3. This receiver must be registered in the manifest and described in the project as a separate file class.
    4. In the receiver display a notification

    Here is all the necessary code: https://ru.stackoverflow.com/a/534643/17609

    • AlarmManager is not destroyed when you turn off the phone or in case of lack of memory? - Arsen Shogenov
    • Should not ...... - YuriySPb
    • On the Internet they write that, yes. Maybe it is better to create a service, to prescribe in the manifest so that it loads after rebooting the phone and at the time of loading it generates the necessary dates and creates an AlarmManager for them? - Arsen Shogenov
    • @ArsenShogenov, the moment of reset is taken by the receiver. What is the point of launching a service from it, if it is possible to set up alarms? - Yuriy SPb
    • Dates are generated, say, a payment schedule. We will schedule the AlarmManager so that on those dates the program sends a response to the receiver. Close the application. Then the user changes something in the application, other dates are generated, tasks that the user has scheduled have to be canceled, and then schedule again on other dates. To cancel a task, you need to know pendingIntent, which is destroyed along with the activation. In the meantime, the Service is alive, it can store pendingIntent, when the service is destroyed in OnDestroy, we cancel everything and generate it again in StartCommand. Is it correct or? - Arsen Shogenov