- Cordova - Best Practices
- Cordova - Whitelist
- Cordova - Vibration
- Cordova - Splash Screen
- Cordova - Network Information
- Cordova - Media Capture
- Cordova - Media
- Cordova - InAppBrowser
- Cordova - Globalization
- Cordova - Geolocation
- Cordova - File Transfer
- Cordova - File System
- Cordova - Dialogs
- Cordova - Device Orientation
- Cordova - Accelerometer
- Cordova - Device
- Cordova - Contacts
- Cordova - Camera
- Cordova - Battery Status
- Cordova - Plugman
- Cordova - Back Button
- Cordova - Events
- Cordova - Storage
- Cordova - Config.xml File
- Cordova - First Application
- Cordova - Environment Setup
- Cordova - Overview
- Cordova - Home
Cordova Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Cordova - Events
There are various events that can be used in Cordova projects. The following table shows the available events.
S.No | Events & Details |
---|---|
1 | deviceReady This event is triggered once Cordova is fully loaded. This helps to ensure that no Cordova functions are called before everything is loaded. |
2 | pause This event is triggered when the app is put into background. |
3 | resume This event is triggered when the app is returned from background. |
4 | backbutton This event is triggered when the back button is pressed. |
5 | menubutton This event is triggered when the menu button is pressed. |
6 | searchbutton This event is triggered when the Android 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 almost the same way. We should always add event psteners in our js instead of the inpne event calpng since the Cordova Content Security Popcy doesn t allow inpne Javascript. If we try to call event inpne, the following error will be displayed.
![Event Error](/cordova/images/event-error.jpg)
The right way of working with events is by using addEventListener. We will understand how to use the volumeupbutton event through an example.
document.addEventListener("volumeupbutton", callbackFunction, false); function callbackFunction() { alert( Volume Up Button is pressed! ); }
Once we press the volume up button, the screen will display the following alert.
![Event Volume Up](/cordova/images/event-volume-up.jpg)
Handpng Back Button
We should use the Android back button for app functionapties pke returning to the previous screen. To implement your own functionapty, we should first disable the back button that is used to exit the App.
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 will appear on the screen instead of exiting the app. This is done by using the e.preventDefault() command.
![Event Back Button](/cordova/images/event-back-button.jpg)