Note that there are some explanatory texts on larger screens.

plurals
  1. POTitanium: Trap android back button
    text
    copied!<p>I'd like to capture the android back button to force confirmation before exiting the app. My app is a two window/two tab app, based on the skeleton that the titanium cli creates. I've tried all three approaches below. As far as I can tell, the back button is never trapped, the app just closes when the back button is pressed.</p> <p>Titanium 3.2.0 CLI OS X 10.9</p> <pre><code> // below true of all windows: // modal: true, // exitOnClose:true // android:back and androidback have been tried Ti.App.addEventListener('androidback', function(e){ var confirmClear = Titanium.UI.createAlertDialog({ message:'Exit App?', buttonNames: ['Yes','No'] }); confirmClear.show(); confirmClear.addEventListener('click',function(e) { if (e.index === 0) { win1.close(); } }); }); ////////////////////////////////////////////////// win1.addEventListener('androidback', function(e){ var confirmClear = Titanium.UI.createAlertDialog({ message:'Exit App?', buttonNames: ['Yes','No'] }); confirmClear.show(); confirmClear.addEventListener('click',function(e) { if (e.index === 0) { win1.close(); } }); }); ////////////////////////////////////////////////// win2.addEventListener('androidback', function(e){ var confirmClear = Titanium.UI.createAlertDialog({ message:'Exit App?', buttonNames: ['Yes','No'] }); confirmClear.show(); confirmClear.addEventListener('click',function(e) { if (e.index === 0) { win2.close(); } }); }); </code></pre> <p>After reading the suggestions, here's my now working code:</p> <pre><code>tabGroup.addEventListener('androidback', function(e){ var confirmClear = Titanium.UI.createAlertDialog({ message:'Exit App?', buttonNames: ['Yes','No'] }); confirmClear.show(); confirmClear.addEventListener('click',function(e) { if (e.index === 0) { tabGroup.close(); } }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload