how to handle device back button on sencha touch application

atluriajith picture atluriajith · Aug 3, 2012 · Viewed 12.4k times · Source

In Sencha touch if I use navigation view i can get back button. This is pretty fine.

But what if user hit device backbutton? it is direct exiting the applicaiton. In my requirement it should not exit the application it has to go back to previous screen.How can i do this?.

Answer

tonymayoral picture tonymayoral · Sep 26, 2013

You can handle hardware back button like this:

if (Ext.os.is('Android')) {
    document.addEventListener("backbutton", Ext.bind(onBackKeyDown, this), false);

    function onBackKeyDown(eve) {

        eve.preventDefault();

        //do something
        alert('back button pressed');

    }
}