This is a migrated thread and some comments may be shown as answers.

android back button

2 Answers 238 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 28 Jul 2014, 09:57 PM
Is there any way to control what the device back button does on an app?

We have a lot of modals and dynamic DOM manipulations that really alter the intuitive flow of the navigation. Is it possible to define where "back" goes? Or better yet, to have it trigger some JavaScript behavior within the app?

2 Answers, 1 is accepted

Sort by
0
Martin Yankov
Telerik team
answered on 31 Jul 2014, 11:34 AM
Hello Michael,

You can use the Cordova backbutton event by adding an event listener to it. This event is fired when the hardware back button is tapped. You can find more information regarding the event and sample code here.

The code for navigation inside the backbutton event handler depends largely on the js framework you are using. If you are using Kendo Mobile, you can use the navigate() function. It provides functionality to navigate to remote and local views and to navigate back to the previous view. You can view and try out code samples of the navigate() function here.

Depending on your scenario, you can also use the replace() method. It navigates to a chosen remote or local view, but also removes the current view from the navigation history. This means that the back button will skip the replaced view. You can see a code sample of the replace() function here.

Let me know if these work for you. If you are having trouble with achieving your goal, please open a support ticket and provide us your project and clear instructions regarding what you want to achieve. We can review it and provide a more concrete solution.

I am looking forward to your reply.

Regards,
Martin Yankov
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
KC
Top achievements
Rank 2
answered on 03 Sep 2014, 04:12 PM
Hello Martin,

    I have taken over mobile development from Michael. I was able to fix this by changing all the 'div's to views from modal-views and adding an initial view to the kendo.mobile.Application. The last one was the big one in order to get the navigation started.

Thanks for the advice.

KC
Tags
Apache Cordova
Asked by
Michael
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
KC
Top achievements
Rank 2
Share this question
or