I have recently started development with titanium appcelerator for developing Android application. And got stuck in a problem that seems to be very minor issues for other who are well versed with Titanium but it have created a headache for me being a beginner.
I have two window named main and subwindow.On button click i am redirected to subwindow from main window. Now whenever I am pressing back button on emulator from subwindow. I have written logic for closing current window i.e subwindow so that I can view main window. That works fine even subwindow closes successfully and even I can view main window. But now if I am trying to click button in main window that doesn't happen.
Even I tried to catch focus event in main window that happens when application is initially loaded but when i am in subwindow and closing subwindow, file focus event is not triggered in main window.
HERE GOES MY CODE
APP.JS
var win1 = Titanium.UI.createWindow({
backgroundColor:'black'
});
var btngo=Ti.UI.createButton({
title : "Go !!!!",
top : "30%"
});
var lbltitle=Ti.UI.createLabel({
text : "This is home page",
font : {fontSize : "20%"} ,
top : "20%",
color : 'white'
});
//Event listener for adding clicking event
btngo.addEventListener('click',function(e){
var nextwindow=Ti.UI.createWindow({
url : "window.js"
});
nextwindow.open();
});
win1.addEventListener('focus',function(e)
{
alert("main window focused");
});
win1.addEventListener('android:back', function (e)
{
win1.close();
});
win1.add(lbltitle);
win1.add(btngo);
win1.open();
WINDOW.JS
var childwindow=Ti.UI.createWindow({
backgroundColor : "white"
});
var btnhome=Ti.UI.createButton({
title : "HOME PAGE"
});
var lbltitle=Ti.UI.createLabel({
text : "This is child window",
font : {fontSize : "20%"} ,
top : "20%",
color : 'white'
});
//For adding event listener for detecting click on home page button
btnhome.addEventListener('click',function(e){
childwindow.close();
});
//Adding event listener for detcting back button click in android
childwindow.addEventListener('android:back', function (e) {
childwindow.close();
});
childwindow.add(lbltitle);
childwindow.add(btnhome);
childwindow.open();
Hope that I would get solution to my problem as soon as possible.
You're creating an opening another window inside the window.js. Probably this is the problem. Try changing your window.js
file as follows
var childwindow=Ti.UI.currentWindow;
childwindow.backgroundColor = 'white'; //You may specify the same while creating the window
var btnhome=Ti.UI.createButton({
title : "HOME PAGE"
});
var lbltitle=Ti.UI.createLabel({
text : "This is child window",
font : {fontSize : "20%"} ,
top : "20%",
color : 'white'
});
//For adding event listener for detecting click on home page button
btnhome.addEventListener('click',function(e){
childwindow.close();
});
//Adding event listener for detcting back button click in android
childwindow.addEventListener('android:back', function (e) {
childwindow.close();
});
childwindow.add(lbltitle);
childwindow.add(btnhome);
Hope this will do the trick :)