# Power Management

The device conserves power by sleeping after a period of inactivity-- primarily, the absence of user interaction such as gestures, touches, or keyboard input. The user can set a preference to trigger sleep after a minimum of 30 seconds or a maximum of 3 minutes. Some system services, such as audio or video playback, will defer sleep. If you need to keep the device awake, you can use the activityStart() and activityEnd() methods in the Power Management service.

Use these service methods if your application performs an extended operation, such as syncing or downloading a lot of data. You will also use this in background applications where you need more than the few seconds allotted during an alarm wakeup.

## Using the Power Management Service

Alert the Power Management service that you are starting an activity that will require the device to stay awake.

>     this.controller.serviceRequest("palm://com.palm.power/com/palm/power", {
>       method: "activityStart",
>       parameters: {
>           id: "com.palm.app.news.update-1",
>           duration_ms: '120000'
>       },
>       onSuccess: this.activitySuccess.bind(this),
>       onFailure: this.activityFailure.bind(this)
>     });

Provide a unique ID (your application ID) with an activity name and an occurrence count. This format allows you to distinguish between requests and manage multiple requests if needed. The only requirement is that the ID string be unique. The activity's expected duration is provided in milliseconds and cannot exceed 900,000 milliseconds (15 minutes).

The power management service automatically terminates your activity request at the end of its duration or 15 minutes, whichever is shorter. You should notify the service when your activity completes, as every bit of power efficiency is important.

>     this.controller.serviceRequest("palm://com.palm.power/com/palm/power", {
>       method: "activityEnd",
>       parameters: {
>           id: "com.palm.app.news.update-1"
>       },
>       onSuccess: this.activitySuccess.bind(this),
>       onFailure: this.activityFailure.bind(this)
>     });

The only parameter is the id provided to the activityStart() method. Activities are not canceled when an application is closed, so you should use activityEnd() in your cleanup() method when there are any outstanding activity requests.