Oracle ADF Mobile: Add “Back” button support for Android

Congratulations! You have developed an application in ADF Mobile.

You deploy it to an iPhone, and it works great.
Now you run it on Android, where your users are used to Android’s “Back” button and opps – Unhappy users.

What’s the fastest way to add support for the back button in order to preserve the same behavior that Android users are used to?

I found this blog post by Deepak Siddappa very helpful. I used it and made some small modifications.

Here are the steps to add “Back” button support to your application:

1. Right-click on the ViewController project, and in the New Gallery window select Web Tier -> HTML -> JavaScript File and name it as “back.js”1

2. Expand ViewController -> Application Sources- > META-INF

3. Click on the adfmf-feature.xml file to launch the Feature editor.

backbutton2

4. Under the Features table, click the Content tab.

5. In the Includes section, click the green plus sign and insert the “back.js” JavaScript file.

backbutton3

6. Open the “back.js” file and paste the below code:

//This is an event that fires when the user presses the device back button
document.addEventListener(“deviceready”, onDeviceReady, false);function onDeviceReady() {
document.addEventListener(“backbutton”, backKeyDown, true);
}function backKeyDown() {
//back on all pages, exit on Logon
if ($(‘#logon’).length)
{
var cFirm = confirm(“Are you sure you want to exit the application?”);
if (cFirm == true) {
//Code to exit the application
navigator.app.exitApp();
}
}
else
{
adf.mf.api.amx.doNavigation(“__back”);
}
}
function onInvokeSuccess(param) {
//To do code after success
};

function onFail() {
//To do code after failure
};

7. This code catches the “Back” button event and navigates to “__back.”

8. If the AMX page’s name is “logon,” then it asks for confirmation to exit the application.

9. To set the name for the first AMX page (logon in this case):

  • Open the AMX Page
    backbutton4
  • Click on the Panel View
  • Under “Panel Page – Properties Inspector” set Id to your preferred name (in this case logon)
    backbutton5

And that’s it! You have now added “Back” button support to your application.

Let us know how it worked for you in our comments section!

Oracle ADF Mobile: Add “Back” button support for Android
Article Name
Oracle ADF Mobile: Add “Back” button support for Android
Description

Congratulations! You have developed an application in ADF Mobile. You deploy it to an iPhone, and it works great. Now you run it on Android, where your users are used to Android’s “Back” button and opps

Author
Publisher Name
auraplayer
Publisher Logo

David Buch
Senior Products Manager

David, our Senior Products Manager, is a highly experienced professional specializing in product definition, innovations, and development, with broad customer understanding, and skillful people management. He has over 20 years of R&D work experience, and continues to excel in his expertise. Before starting his career, David attended Bar-Ilan University where he studied computer science and economics. When he is not working, David enjoys spending his time as a professional tuba player joining symphony orchestras and chamber ensembles.

Elizabeth Pearl
Relationship Manager

A Relationship Manager, but a teacher by degree, Elizabeth is passionate about technology and always seeks to educate and improve the lives of others. During her years as a teacher, Elizabeth learned valuable skills that she applies to everyday life and her role at AuraPlayer: active listening, organization, preparation, and clear communication. Elizabeth is originally from the United States but currently resides in England. In her spare time, she loves exercising, spending time with her family and friends, and playing volleyball.

Nathalie Wasserman
CFO & Operations Manager

Natalie is proud to be AuraPlayer’s Operations and Chief Financial Officer. She takes pride in her work, and loves being a part of the AuraPlayer family. Prior to working at AuraPlayer, Nathalie worked at various companies as an accountant. She attended the University College London (UCL), where she graduated with a Bachelor’s Degree in economics and business. She then went on to pursue a Master’s degree in Political Economies in Eastern Europe. 

Gwen Edwards
VP Business Development

An expert in helping businesses seize their potential and grow, Gwen is committed to take AuraPlayer to the next level. With over 30 years of experience in the high technology sector and working with Fortune 500 companies, she works as an advisor for growing businesses to help enhance their value and reach their business objectives. She’s a dynamic member of our team, leveraging her sales and marketing, and P&L experience to our current and future product suite.

Gwen also serves on a several private company boards in Silicon Valley, and is an active member of the angel investment network, Golden Seeds.

Yossi Nakash
CTO & Co-Founder

A true developer, Yossi has been developing and coding in Java / J2EE, C++, .Net, and C# for over 15 years, focusing mainly on the RD side of things. Entering the Oracle World about 5 years ago, Yossi immersed himself in the world of Oracle SOA, Weblogic, ADF and ADF Mobile, as well as the Java side of things.

Prior to joining Mia to found AuraPlayer, Yossi held the role of RD team leader at RadView and was a Java developer at Motorola.