Hi,I am developing android application with Titanium, android sdk 1.8.0.1.In my application there are three tabs.Every Time when I click on tab my window get refreshed.So my code structure looks like:
////// m.js ///////////////// var explore = Titanium.UI.createWindow( { //navBarHidden:true, backgroundColor:'#f8f8f8' });explore.open({animated:true}); Ti.App.addEventListener('feed_partial_action',function(e) { alert('inside event') }) var new = Titanium.UI.createButton( { });explore.add(new); new.addEventListener('click', function(e) { var explore_new = Titanium.UI.createWindow( { navBarHidden:true, backgroundColor:'#f8f8f8' });explore_new.open({animated:true}); });
/////// explore_new.js///////////////// var explore_new = Titanium.UI.currentWindow; Ti.App.fireEvent('feed_partial_action',{page_type:'new'});so my problem is that on first load alert inside the event listner in m.js executed once but when I again call m.js it shows alert twice.on third time it shows alert 3 times and so on and after some time it forcefully close the app.I think event listener of window still open after refreshing widow.So is there any way to handle this problem.Thank you
3 Answers
Accepted Answer
hi nilesh,
this can be happened because when m.js window open then feed_partial_action add every time but you did not remove that listener so try this
var test = function(e){ alert(' << TEST >> '); } Ti.App.addEventListener('feed_partial_action',test);and on the close event of the window
explore.addEventListener('close',function(e){ Ti.App.removeEventListener('feed_partial_action',test); });
Hi Nilesh,
When you call m.js you are actually creating one more window because of every time you have created window in m.js.Try to use like this that may help you.
var explore = Titanium.UI.currentWindow;
This worked fine for me. Try this too. :)
var test = function(e) {
alert(' TEST ');
Ti.App.removeEventListener('feed_partial_action', test);
}
Ti.App.addEventListener('feed_partial_action', test);
Your Answer
Think you can help? Login to answer this question!