Cordova Events - Cordova

What is Cordova Events?

There are various events that can be used in Cordova projects. The following table shows the available events.

Cordova Events

SN

Events & Details

1

deviceReady

The event is triggered once the Cordova is fully loaded. This helps to ensure that no Cordova functions are called before everything is loaded.

2

pause

The event is triggered when the app is put into background.

3

resume

The event is triggered when the app is returned from background.

4

backbutton

The event is triggered when the back button is pressed.

5

menubutton

The event is triggered when menu button is pressed.

6

searchbutton

The event is triggered when the Android search button is pressed.

7

startcallbutton

The event is triggered when the start call button is pressed.

8

endcallbutton

The event is triggered when the end call button is pressed.

9

volumedownbutton

The event is triggered when the volume down button is pressed.

10

volumeupbutton

The event is triggered when the volume up button is pressed.

Using Events

All of the events are used in similar way. We should always add event listeners in our js instead of inline event calling since Cordova Content Security Policy doesn't allow inline Javascript. If we try to call event inline, we will get the following error.
Cordova - Events

The right way of working with events is by using addEventListener. We will show you example of using volumeupbutton event.

Once we press the volume up button, the alert will be shown on screen.


Cordova - Events

Handling Back Button

You will usually want to use Android back button 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.

Now when we press the native Android back button, the alert will appear on screen instead of exiting the app. This is done by using e.preventDefault().
Cordova - Events

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Cordova Topics