Hi i am working on android application development.I am using Titanium studio for development. I create a simple application.I want to capture the device back button event in my application because I don't want to user android default tabs in titanium.I am creating my own tabs.I tried following code :
:list.js
var expt = Titanium.UI.currentWindow;
expt.addEventListener('android:back', function (e)
{
Ti.App.fireEvent('expt_back_event');
});
:app.js
Ti.App.addEventListener('expt_back_event',function(e)
{
alert('hiiii in side event listener');
});
But its not working instead of giving pop-up it closed my application which I don't want. Is there any way to obtain this result.
You have to cancel the bubble of the event.
mainWindow.addEventListener('android:back', function(e) {
e.cancelBubble = true;
Ti.App.fireEvent('android_back_button');
});
Related
I'm trying to control how the android hardware back button behaves in my app. I had it all working but now I can't reproduce it. The code I'm using is in app.js. I'm expecting the back button to do nothing but write to the console.
.run(function($ionicPlatform) {
$ionicPlatform.onHardwareBackButton(function() {
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!")
});
Can any one see what the problem is? I'm running ionic CLI v1.7.11. I'm running the code with ionic view on android
You can find full details, including a full working solution for both hard & soft back buttons at my related post:
Ionic override all BACK button behaviour for specific controller
To summarise how I handled the hardware back button, the trick is to register an action for the Back button, using code like this:
var doCustomBack= function() {
// do something interesting here
};
// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterHardBack= $ionicPlatform.registerBackButtonAction(
doCustomBack, 101
);
$scope.$on('$destroy', function() {
deregisterHardBack();
});
The actual setting is done in that second block calling $ionicPlatform.registerBackButtonAction().
This returns a method that can be called to deregister the action later on if you want to.
It was a ionic view problem. Seems it does not support this.
I am newbie in cordova. I am trying to develop a mobile application which need to support for all platform.
I am facing a problem while trying to change the two pages in transition reverse mode.
In below android version 4.4.2 and ios platform developed app is working fine. But in above android 5.0 version and windows platform it showing blank page like below image.
Its happening when the user hitting the back button from mobile. jquery function for transition reversing which is mentioned below.
$.mobile.changePage("#mainpage" , { transition: "slide" ,reverse="true"} );
If I removed the argument reverse=true for above android 5.0 version, the transition reverse mode working fine with below function.
$.mobile.changePage("#mainpage" , { transition: "slide" } );
I am using jquery1.3.0 version, cordova5.1.1.
Is there is any way to fix the issue for different android version and other platform.
Please let me know.
Use the following method to do so.. it will work on device's back key down, and if you want to add button on UI for back, then you can call onBackKeyDown() on click event of that button
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
console.log('Device ready - register onBackKeyDown()');
}
document.addEventListener("deviceready", onDeviceReady, false);
function onBackKeyDown() {
try{
var nav = window.navigator;
if( this.phonegapNavigationEnabled && nav && nav.app && nav.app.backHistory )
{
nav.app.backHistory();
}
else
{
window.history.back();
}
}
catch(e)
{
alert(e);
}
}
I have 2 buttons in my app ( my app published by flash cs6 for android ). one button for exit app and one button for minimize app (send app to background and show homepage).what is code for 2nd button in as3?
b1.addEventListener(MOUSE_UP,exitapp);
b2.addEventListener(MOUSE_UP,minimizeapp);
function exitapp(e:mouseevent)
{
nativeapplication.nativeapplication.exit();
}
function minimizeapp(e:mouseevent)
{
//...what code I should write here?
}
NativeApplication has a property called activeWindow which is an instance of NativeWindow which has a minimize method:
function minimizeapp(e:mouseevent)
{
nativeapplication.activeWindow.minimize();
}
Finally I find this solution:
https://forums.adobe.com/message/5714697#5714697
In my Phonegap app, created in a single html file using div as pages, I override the Back button to exit the app, only if the div that acts as the Home page is visible, otherwise to hide the others and show the home div. I use jQuery to attach the event handlers.
It works well at first app launch, but if the app is in the History list, the override is not working, the Back button exits the app without checking which div is visible. After deleting the app from the History list it works as expected again.
Tested on Nexus 4 with Android 4.2.
Here is the code:
$(document).on('backbutton', function (ev) {
ev.preventDefault();
if (!$('#divHomeScreen').is(':visible')) {
$('.screen').hide();
$('#divHomeScreen').show();
return false;
} else {
navigator.app.exitApp();
}
});
Thanks for your help.
What I have done is dynamically add and remove the backbutton handler as needed. For example...
function showScreen()
{
$("#divHomeScreen").hide();
$(".screen").show();
$(document).on("backbutton", onBackButton);
}
function hideScreen()
{
$(".screen").hide();
$("#divHomeScreen").show();
$(document).off("backbutton", onBackButton);
}
function onBackButton()
{
hideScreen();
}
This was tested on Galaxy S3 Android 4.3 and PhoneGap 3.3.0
I am working Android mobile application using Titanium studio.I have developed small application.After logging into application will display two tabs on my new window; after clicking any other tab it opens correct window.But when I click device back button (back button on my android phone simulator) it not closes my application. it render one blank window and if I again click back button it closes my application
after log in successful I used window-name.close(); so that it not render again sign in form. But I am using .close() for only sign in window so that after clicking back it will not show sign in page again.
var user1 = Ti.UI.createWindow
({
navBarHidden : false,
url:'main.js',
});user1.open();
w.close();
home.close();
========== main=============
var mainTabGroup = Titanium.UI.createTabGroup();
var feedWin = Titanium.UI.createWindow({
url:'home/feed.js'
});
var feedTab = Titanium.UI.createTab({
title:'Feed',
window:feedWin
});
var listWin = Titanium.UI.createWindow({
url:'home/list.js'
});
var listTab = Titanium.UI.createTab({
title:'List',
window:listWin
});
mainTabGroup.addTab(feedTab);
mainTabGroup.addTab(listTab);
mainTabGroup.open();
you need to set
exitOnClose:true
on whichever window you want to trigger the closing of the app when that window is closed
From the appcelerator documentation, Titanium.UI.Window
(Android only.) Boolean indicates if the application should exit when
the Android back button is pressed while the window is being shown.
You can only set this as a createWindow({...}) option. Setting it
after window creation will no effect.