---
title: "Handling Events in App Built Using Apache Cordova"  
description: "In the series of learning, building apps using Apache Cordova, this article will explain you which events you can use in Cordova and how to use them.T"  
author: "Anonymous User"  
published: 2017-04-18  
updated: 2018-03-19  
canonical: https://www.mindstick.com/blog/11355/handling-events-in-app-built-using-apache-cordova  
category: "apache cordova"  
tags: ["mobile development", "apache", "cordova", "apache cordova"]  
reading_time: 3 minutes  

---

# Handling Events in App Built Using Apache Cordova

In the series of learning, building apps using Apache Cordova, this article will explain you which events you can use in Cordova and how to use them.

There are numerous events that can be used in Cordova [mobile application](https://www.mindstick.com/forum/201/namespace-for-mobile-application-in-dot-net) projects.

**The events available are listed in the following table.**

**Apache Cordova Events**

| ## SN | ## Events & Details |
| --- | --- |
| 1 | **deviceReady** This event is invoked when the Cordova is fully loaded. This ensures that no other Cordova [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) are called before everything is loaded. |
| 2 | **pause** This event is triggered when the app is made run into [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp). |
| 3 | **resume** This event is triggered when the app is resumed from background running. |
| 4 | **backbutton** This event is triggered when the back button is pressed. |
| 5 | **menubutton** This event is triggered when menu button is pressed. |
| 6 | **searchbutton** This event is triggered when the Android [search button](https://answers.mindstick.com/qa/34597/what-is-site-search-button) is pressed. |
| 7 | **startcallbutton** This event is triggered when the start call button is pressed. |
| 8 | **endcallbutton** This event is triggered when the end call button is pressed. |
| 9 | **volumedownbutton** This event is triggered when the volume down button is pressed. |
| 10 | **volumeupbutton** This event is triggered when the volume up button is pressed. |

**Using Events**

All of the events are used in the same manner. you should always add [event listeners](https://www.mindstick.com/forum/159117/how-do-you-handle-events-using-jquery-and-attach-event-listeners-to-elements) in our js file in place of inline event calling since Cordova **[Content Security](https://answers.mindstick.com/qa/112149/how-do-i-implement-content-security-policy-csp-to-prevent-xss-attacks) Policy** doesn't allow inline Javascript.

The correct way of handling with events is by using **addEventListener**. We will show you example of using volumeupbutton event.

```
document.addEventListener("volumeupbutton", callbackFunction, false);
function callbackFunction(){
   alert('Volume Up Button is pressed!')
}
```

**When you press the volume up button, You will see the following on the screen.**

![Handling Events in App Built Using Apache Cordova](https://www.mindstick.com/blogs/0eb225c3-c5d3-4966-9b8c-b9f0466d31a2/images/a9fd9bed-02de-49cb-b77c-6184f6497a79.png)\

**Handling Back Button**

You generally want to use back button in your app for some app functionality like returning to previous screen. To be able to implement your own functionality, you first need to disable exiting the app when the back button is pressed.

```
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {   e.preventDefault();   alert('Back Button is Pressed!');}
```

Now when we press the native Android back button, the alert message will appear on screen in place of exiting the app. This is done by using a finction called **e.preventDefault().**

![Handling Events in App Built Using Apache Cordova](https://www.mindstick.com/blogs/0eb225c3-c5d3-4966-9b8c-b9f0466d31a2/images/9646c715-071f-47e4-9faa-1104b4dd92ee.png)\

## *\*

***Read Our Previous Posts***:[Introduction to Apache Cordova](https://www.mindstick.com/blog/11351/mobile-application-development-using-apache-cordova)\

[How to Install Apache Cordova](https://www.mindstick.com/blog/11352/how-to-install-and-setup-apache-cordova)

[Create First App Using Apache Cordova](https://www.mindstick.com/blog/11353/creating-first-application-using-cordova)

[Apache Cordova- Storing Data Through Apps](https://www.mindstick.com/blog/11354/apache-cordova-storing-data-through-apps)

---

Original Source: https://www.mindstick.com/blog/11355/handling-events-in-app-built-using-apache-cordova

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
