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!

About these ads

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

    • how to navigate to view via java coding in Adf mobile , Give me a code if we have login form and display two different view on login success and failed

      • You have to add action Listener on a managed Java bean, and inside your code, when you decide to navigate, you will return “” with the name of the “Control flow name” that is the name of the navigation in the “Task Flow diagram”.. that would navigate to the expected View

      • You have to add action Listener on a Java bean, and inside your code, when you decide to navigate, return “” with the name of the “Control flow name” in the “Task Flow”.. that would navigate to the expected View

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s