## When to Use<a name="section18502174174019"></a>
You can set your application to call the **ReminderRequest** class to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background, even when your application is frozen or exits.
## Available APIs<a name="section1633115419401"></a>
**reminderAgent** encapsulates the methods for publishing and canceling reminders.
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p13562171015712"><aname="p13562171015712"></a><aname="p13562171015712"></a>Publishes a scheduled reminder.</p>
<pid="p9591131611311"><aname="p9591131611311"></a><aname="p9591131611311"></a>The maximum number of valid notifications (excluding expired ones that will not pop up again) is 30 for one application and 2000 for the entire system.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p3465939173317"><aname="p3465939173317"></a><aname="p3465939173317"></a>Cancels a specified reminder. (The value of <strongid="b83631346162614"><aname="b83631346162614"></a><aname="b83631346162614"></a>reminderId</strong> is obtained from the return value of <strongid="b236420465267"><aname="b236420465267"></a><aname="b236420465267"></a>publishReminder</strong>.)</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p184651639143320"><aname="p184651639143320"></a><aname="p184651639143320"></a>Obtains all valid reminders set by the current application.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p19451839143310"><aname="p19451839143310"></a><aname="p19451839143310"></a>Cancels all reminders set by the current application.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p142081320344"><aname="p142081320344"></a><aname="p142081320344"></a>Registers a <ahref="../nottoctopics/en-us_topic_0000001180018813.md#section1382174172015">NotificationSlot</a> instance to be used by the reminder.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p1407141783410"><aname="p1407141783410"></a><aname="p1407141783410"></a>Removes a <ahref="../nottoctopics/en-us_topic_0000001180018813.md#section1382174172015">NotificationSlot</a> instance of a specified type.</p>
</td>
</tr>
</tbody>
</table>
**ActionButtonType** enumerates types of buttons displayed in a reminder notification.
<tdclass="cellrowborder"valign="top"width="61.809999999999995%"headers="mcps1.2.3.1.2 "><pid="p13547161217154"><aname="p13547161217154"></a><aname="p13547161217154"></a>Close button, which can be tapped to stop the reminder alert tone, close the reminder notification, and cancel the reminder snoozing.</p>
<tdclass="cellrowborder"valign="top"width="52.04%"headers="mcps1.2.5.1.4 "><pid="p16804121112213"><aname="p16804121112213"></a><aname="p16804121112213"></a>Text on the button.</p>
<tdclass="cellrowborder"valign="top"width="51.66483351664834%"headers="mcps1.2.5.1.4 "><pid="p24967514355"><aname="p24967514355"></a><aname="p24967514355"></a>Name of the package redirected to when the reminder notification is clicked.</p>
<tdclass="cellrowborder"valign="top"width="51.66483351664834%"headers="mcps1.2.5.1.4 "><pid="p14966511359"><aname="p14966511359"></a><aname="p14966511359"></a>Name of the ability redirected to when the reminder notification is clicked.</p>
</td>
</tr>
</tbody>
</table>
**MaxScreenWantAgent** sets the name of the target package and ability to start automatically when the reminder arrives and the device is not in use. If the device is in use, a notification will be displayed.
<tdclass="cellrowborder"valign="top"width="51.300000000000004%"headers="mcps1.2.5.1.4 "><pid="p13390173423710"><aname="p13390173423710"></a><aname="p13390173423710"></a>Name of the package that is automatically started when the reminder arrives and the device is not in use.</p>
<tdclass="cellrowborder"valign="top"width="51.300000000000004%"headers="mcps1.2.5.1.4 "><pid="p639093443717"><aname="p639093443717"></a><aname="p639093443717"></a>Name of the ability that is automatically started when the reminder arrives and the device is not in use.</p>
</td>
</tr>
</tbody>
</table>
**ReminderRequest** defines the reminder to publish.
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p1019193963812"><aname="p1019193963812"></a><aname="p1019193963812"></a>Type of the reminder.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p3191133963820"><aname="p3191133963820"></a><aname="p3191133963820"></a>Action button displayed in the reminder notification.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p819218395387"><aname="p819218395387"></a><aname="p819218395387"></a>Information about the ability that is redirected to when the notification is clicked.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p119213933815"><aname="p119213933815"></a><aname="p119213933815"></a>Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p2286115418440"><aname="p2286115418440"></a><aname="p2286115418440"></a>Extended content to be displayed when the reminder expires.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p66021050104419"><aname="p66021050104419"></a><aname="p66021050104419"></a>Extended content to be displayed when the reminder is snoozing.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p16327733456"><aname="p16327733456"></a><aname="p16327733456"></a>Notification ID used by the reminder. For details, see the API reference of the <strongid="b1391142771410"><aname="b1391142771410"></a><aname="b1391142771410"></a>NotificationRequest.setNotificationId(int id)</strong> method.</p>
<tdclass="cellrowborder"valign="top"width="50.480000000000004%"headers="mcps1.2.5.1.4 "><pid="p193705238459"><aname="p193705238459"></a><aname="p193705238459"></a>Type of the slot used by the reminder</p>
</td>
</tr>
</tbody>
</table>
**ReminderRequestCalendar** extends **ReminderRequest** and defines a reminder for a calendar event.
# Agent-Powered Scheduled Reminder Development
## When to Use
You can set your application to call the **ReminderRequest** class to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background, even when your application is frozen or exits.
## Available APIs
**reminderAgent** encapsulates the methods for publishing and canceling reminders.
| function publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback\<number>): void;<br>function publishReminder(reminderReq: ReminderRequest): Promise\<number>; | Publishes a scheduled reminder.<br>The maximum number of valid notifications (excluding expired ones that will not pop up again) is 30 for one application and 2000 for the entire system. |
| function cancelReminder(reminderId: number, callback: AsyncCallback\<void>): void;<br/>function cancelReminder(reminderId: number): Promise\<void>; | Cancels a specified reminder. (The value of **reminderId** is obtained from the return value of **publishReminder**.) |
| function getValidReminders(callback: AsyncCallback<Array\<ReminderRequest>>): void;<br/>function getValidReminders(): Promise<Array\<ReminderRequest>>; | Obtains all valid reminders set by the current application. |
| function cancelAllReminders(callback: AsyncCallback\<void>): void;<br/>function cancelAllReminders(): Promise\<void>; | Cancels all reminders set by the current application. |
| function addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback\<void>): void;<br/>function addNotificationSlot(slot: NotificationSlot): Promise<void>; | Registers a NotificationSlot instance to be used by the reminder. |
| function removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback\<void>): void;function removeNotificationSlot(slotType: notification.SlotType): Promise\<void>; | Removes a NotificationSlot instance of a specified type. |
**ActionButtonType** enumerates types of buttons displayed in a reminder notification.
| ACTION_BUTTON_TYPE_CLOSE | Close button, which can be tapped to stop the reminder alert tone, close the reminder notification, and cancel the reminder snoozing. |
**ReminderType** enumerates the reminder types.
**Table 3** ReminderType enumeration
| Name | Description |
| ---------------------- | ------------------- |
| REMINDER_TYPE_TIMER | Countdown reminder. |
| REMINDER_TYPE_CALENDAR | Calendar reminder. |
| REMINDER_TYPE_ALARM | Alarm reminder. |
**ActionButton** defines a button displayed in the reminder notification.
| pkgName | string | Yes | Name of the package redirected to when the reminder notification is clicked. |
| abilityName | string | Yes | Name of the ability redirected to when the reminder notification is clicked. |
**MaxScreenWantAgent** sets the name of the target package and ability to start automatically when the reminder arrives and the device is not in use. If the device is in use, a notification will be displayed.
| reminderType | ReminderType | Yes | Type of the reminder. |
| actionButton | [ActionButton?, ActionButton?] | No | Action button displayed in the reminder notification. |
| wantAgent | WantAgent | No | Information about the ability that is redirected to when the notification is clicked. |
| maxScreenWantAgent | MaxScreenWantAgent | No | Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed. |
| ringDuration | number | No | Ring duration. |
| snoozeTimes | number | No | Number of reminder snooze times. |
| timeInterval | number | No | Reminder snooze interval. |
| title | string | No | Reminder title. |
| content | string | No | Reminder content. |
| expiredContent | string | No | Extended content to be displayed when the reminder expires. |
| snoozeContent | string | No | Extended content to be displayed when the reminder is snoozing. |
| notificationId | number | No | Notification ID used by the reminder. For details, see the API reference of the **NotificationRequest.setNotificationId(int id)** method. |
| slotType | SlotType | No | Type of the slot used by the reminder. |
**ReminderRequestCalendar** extends **ReminderRequest** and defines a reminder for a calendar event.
For the application to run properly, if both **repeatMonths** and **repeatDays** are not specified, the earliest reminder time must be later than the current time.
<tdclass="cellrowborder"valign="top"width="50.3%"headers="mcps1.2.5.1.4 "><pid="p1031461511522"><aname="p1031461511522"></a><aname="p1031461511522"></a>Reminder time, accurate to the minute.</p>
<tdclass="cellrowborder"valign="top"width="50.3%"headers="mcps1.2.5.1.4 "><pid="p2031411555218"><aname="p2031411555218"></a><aname="p2031411555218"></a>Months in which the reminder repeats. The value range is 1 to 12.</p>
<tdclass="cellrowborder"valign="top"width="50.3%"headers="mcps1.2.5.1.4 "><pid="p18314141515212"><aname="p18314141515212"></a><aname="p18314141515212"></a>Date on which the reminder repeats. The value range is 1 to 31.</p>
</td>
</tr>
</tbody>
</table>
**ReminderRequestAlarm** extends **ReminderRequest** and defines a reminder for the alarm clock.
<tdclass="cellrowborder"valign="top"width="49.86%"headers="mcps1.2.5.1.4 "><pid="p1770161618444"><aname="p1770161618444"></a><aname="p1770161618444"></a>Hour portion of the reminder time. The value range is 0 to 23.</p>
<tdclass="cellrowborder"valign="top"width="49.86%"headers="mcps1.2.5.1.4 "><pid="p17703161445"><aname="p17703161445"></a><aname="p17703161445"></a>Minute portion of the reminder time. The value range is 0 to 59.</p>
<tdclass="cellrowborder"valign="top"width="49.86%"headers="mcps1.2.5.1.4 "><pid="p16101423134917"><aname="p16101423134917"></a><aname="p16101423134917"></a>Days of a week when the reminder repeats. The value range is 1 to 7.</p>
</td>
</tr>
</tbody>
</table>
**ReminderRequestTimer** extends **ReminderRequest** and defines a reminder for a scheduled timer.
<tdclass="cellrowborder"valign="top"width="49.17%"headers="mcps1.2.5.1.4 "><pid="p7214112014509"><aname="p7214112014509"></a><aname="p7214112014509"></a>Number of seconds in the countdown timer.</p>
</td>
</tr>
</tbody>
</table>
**LocalDateTime** defines a **LocalDateTime** instance.
>The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> **NOTE:** The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Module to Import<a name="section7480141454919"></a>
<td class="cellrowborder" valign="top" width="62.91%" headers="mcps1.1.5.1.4 "><p id="p788516491307"><a name="p788516491307"></a><a name="p788516491307"></a>Function to be called after the timer goes off.</p>
<td class="cellrowborder" valign="top" width="62.91%" headers="mcps1.1.5.1.4 "><p id="p1943234615"><a name="p1943234615"></a><a name="p1943234615"></a>Number of milliseconds delayed before the execution. If this parameter is left empty, the default value <strong id="b1264512254010"><a name="b1264512254010"></a><a name="b1264512254010"></a>0</strong> is used, which means that the execution starts immediately or as soon as possible.</p>
<td class="cellrowborder" valign="top" width="62.91%" headers="mcps1.1.5.1.4 "><p id="p139991022863"><a name="p139991022863"></a><a name="p139991022863"></a>Additional parameter to pass to the handler after the timer goes off.</p>
<td class="cellrowborder" valign="top" width="69.94%" headers="mcps1.1.5.1.4 "><p id="p6426183941319"><a name="p6426183941319"></a><a name="p6426183941319"></a>ID of the timer to cancel, which is returned by <strong id="b5804644564"><a name="b5804644564"></a><a name="b5804644564"></a>setTimeout()</strong></p>
| handler | Function | Yes | Function to be called after the timer goes off. |
| delay | number | No | Number of milliseconds delayed before the execution. If this parameter is left empty, the default value **0** is used, which means that the execution starts immediately or as soon as possible. |
| ...args | Array\<any> | No | Additional parameter to pass to the handler after the timer goes off. |
- Return Value
| Type | Description |
| ------ | ----------- |
| number | Timer ID. |
- Example
```
export default {
setTimeOut() {
var timeoutID = setTimeout(function() {
console.log('delay 1s');
}, 1000);
}
```
}
```
## clearTimeout
## setInterval<a name="section3644185910144"></a>
clearTimeout(timeoutID: number): void
setInterval\(handler\[, delay\[, ...args\]\]\): number
Cancels the timer created via **setTimeout()**.
Sets a repeating timer for the system to repeatedly call a function at a fixed interval.
<td class="cellrowborder" valign="top" width="62.91%" headers="mcps1.1.5.1.4 "><p id="p4645155931418"><a name="p4645155931418"></a><a name="p4645155931418"></a>Function to be called repeatedly</p>
<td class="cellrowborder" valign="top" width="62.91%" headers="mcps1.1.5.1.4 "><p id="p13645559141415"><a name="p13645559141415"></a><a name="p13645559141415"></a>Number of milliseconds delayed before the execution</p>
<td class="cellrowborder" valign="top" width="62.91%" headers="mcps1.1.5.1.4 "><p id="p12645105991413"><a name="p12645105991413"></a><a name="p12645105991413"></a>Additional parameter to pass to the handler after the timer goes off</p>
<td class="cellrowborder" valign="top" width="69.94%" headers="mcps1.1.5.1.4 "><p id="p7646459141416"><a name="p7646459141416"></a><a name="p7646459141416"></a>ID of the repeating timer to cancel, which is returned by <strong id="b1855918269134"><a name="b1855918269134"></a><a name="b1855918269134"></a>setInterval()</strong>.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
clearInterval() {
var intervalID = setInterval(function() {
console.log('do very 1s.');
}, 1000);
clearInterval(intervalID);
}
}
```
## setInterval
setInterval(handler[, delay[, ...args]]): number
Sets a repeating timer for the system to repeatedly call a function at a fixed interval.