Hi I'm having a weird thing in my app. Whenever I change the orientation to portrait to landscape or vice versa. The window reload again. Here's my code:
Ti.include('../common.js'); var nowshowingWin = Ti.UI.currentWindow; var url = 'myurl.com'; var json; var rowData = []; var table = Ti.UI.createTableView(); function getMovies(){ var xhr = Ti.Network.createHTTPClient({ onload: function(e) { Ti.API.debug(this.responseText); alert('Hello World'); successConnection(); json = JSON.parse(this.responseText); for (i = 0; i < json.length; i++){ var bgcolor = (i % 2) == 0 ? '#FFF' : '#EEE'; var row = Ti.UI.createTableViewRow({ height:150, backgroundColor:bgcolor, className: "nowShowingRow", width: Titanium.UI.FILL, backgroundFocusedColor: "#b2cb39", focusable: true }); var movie = json[i]; var movie_thumb = Ti.UI.createImageView({ image: movie.thumb_poster, left:15, top:10, bottom: 15, height: 130, width: 100, touchEnabled: false }); var movie_label = Ti.UI.createLabel({ text: movie.title, left:120, top: '5', horizontalWrap: true, width: '100%', height: '25' , textAlign:'left', color: '#000', touchEnabled: false, font: { fontFamily:'HelveticaNeue-Bold', fontSize:18, fontWeight:'bold', ellipsize: true } }); var cast_label = Ti.UI.createLabel({ text: movie.casts, horizontalWrap: true, left:120, height:'20', width: '100%', ellipsize: 'true', top: '30', textAlign:'left', color:'#444444', touchEnabled: false, font: { fontSize:15 } }); var genre_label = Ti.UI.createLabel({ text: (movie.genres ? movie.genres : "-"), left:120, width: '100%', ellipsize: true, top: '45', bottom:15, height:30, textAlign:'left', color:'#444444', touchEnabled: false, font: { fontSize:15 } }); var director_label = Ti.UI.createLabel({ text: 'Directed by ' + movie.director, left:120, width:'100%', ellipsize: true, horizontalWrap: true, top: '72', height: 20, textAlign:'left', color:'#444444', touchEnabled: false, font: { fontSize:15 } }); var criticTomatoImage = ""; if(parseInt(movie.critics_score) >= 60) { criticTomatoImage = "../images/rt-tomato.png"; } else { criticTomatoImage = "../images/rt-tomato-splat.png"; } var rtCritic = Ti.UI.createImageView({ image: criticTomatoImage, left:120, right: 15, top:'95', height:15, width:15, touchEnabled: false }); var rtCriticScore = Ti.UI.createLabel({ text: movie.critics_score + '% Critic', left: 140, top: '90', height:25, right: 50, textAlign:'left', color:'#444444', touchEnabled: false, font: { fontSize:12 } }); // adding objects to the row row.add(movie_thumb); row.add(movie_label); row.add(cast_label); row.add(genre_label); row.add(director_label); row.add(rtCritic); row.add(rtCriticScore); // adding movid objects to the row row.movie = movie; rowData[i]= row; } table.setData(rowData); }, onerror: function(e) { Ti.API.debug(e.error); alert('Hello World'); failedConnection(); }, timeout:5000 }); xhr.open("GET", url); xhr.send(); } nowshowingWin.addEventListener('open', function() { nowshowingWin.add(table); getMovies(); nowshowingWin.backgroundColor = "#FFFFFF"; }); table.addEventListener('click', function(e){ var movieWin = Ti.UI.createWindow({ url: 'movie.js', title: 'Now Showing', }); movieWin.movie = e.row.movie; Ti.UI.currentTab.open(movieWin, {animated:true} ); });I put a alert('Hello World') for the onload and onerror events. Please help me. Thanks!