How to fire android:back or simulate back button click
Is there a way to programmatically trigger an android:back button or simulate as if the user has clicked the back button?
3 Answers
-
Jake
There is indeed a way, and it is described in ticket TIMOB-1641. :)
Cheers
-
I maybe late … to update this here as i see it hasn't been updated since months now. But still this was the first link i came across when searching for a solution. And this is what i did.
Firstly the android:back button actually does more than closing the app. A good read on the action of back button is this THIS.
Add the below line to the "back button"(your custom made button) event listener.var activity = Titanium.Android.currentActivity; activity.finish();
backButton.addEventListener('click', function(){ var activity = Titanium.Android.currentActivity; activity.finish(); });
This works in my case
-
A number of people do not know that the "android:back" window event is not triggered unless the window has "navBarHidden:true" specified. Please ensure that this property is set and then try it out.