Reputation: 563
Im running an Alloy project on a physical device (Samsung Galaxy S4), the opening of windows are incredibly slow on the first open event. For example, opening a window on a button click can take up to 10 seconds depending on "how much stuf" the window contain. But I dont think Im doing anything out of the ordinary though, se sample window below. After the window have been opened once and then closed, the second time it opens almost instantly. As it where somehow "in memory".
Example window:
<Alloy>
<Window>
<View id="container" class="container">
<View id="imageContainer">
<ImageView id="imageView"></ImageView>
</View>
<View id="infoContainer">
<Label id="infoHeaderLabel">L('logged_in_as')</Label>
<View class="divider top5"></View>
<Label id="nameLabel" class="top10"></Label>
<Label id="emailLabel" class="top5"></Label>
<Label id="organizationLabel" class="top5"></Label>
<View class="divider top10"></View>
</View>
<TableView id="tableView">
<TableViewRow identifier="coach" title="L('coach')" hasChild=true if="!Alloy.Globals.usertypeIsCoach && !Alloy.Globals.isFreeTierUser"></TableViewRow>
<TableViewRow identifier="export" title="L('button_export')" hasChild=true if="Alloy.Globals.localDatabaseDoesExist"></TableViewRow>
<TableViewRow identifier="logout" title="L('button_logout')" hasChild=true></TableViewRow>
</TableView>
</View>
</Window>
var args = $.args;
var arrowdb = require('arrowdb');
var Util = require('utilities');
function setUserInformation(){
$.imageView.image = Alloy.Globals.getOrganization() ? Alloy.Globals.getOrganization().image_url : '';
var user = Alloy.Globals.getUser();
$.nameLabel.text = user.firstName +' '+user.lastName;
$.emailLabel.text = user.email;
$.organizationLabel.text = Alloy.Globals.getOrganization() ? Alloy.Globals.getOrganization().name : '';
}
setUserInformation();
function showLogoutDialog() {
var dialog = Ti.UI.createAlertDialog({
cancel : 0,
buttonNames : [L('button_cancel'),L('button_logout')],
title : L('confirm')
});
dialog.addEventListener('click', function(e) {
if (e.index === 1) {
logoutUser();
}
});
dialog.show();
}
function logoutUser() {
arrowdb.logout().then(function(result){
if(result.success){
Alloy.Globals.removeUser();
Util().showLoginWindow();
}
}, function(error){
alert(error);
});
}
// ----------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------- EVENT LISTENERS --------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------
$.tableView.addEventListener('click', function(e){
switch(e.source.identifier){
case 'coach':
var chooseCoachController = Alloy.createController('chooseCoach').getView();
chooseCoachController.open();
break;
case 'logout':
showLogoutDialog();
break;
}
});
The window do require two other files which are just Utility modules, where "arrowdb" has dependencies and require in moment, ti.cloud and Q libary, but still I dont think thats such a lot of code to take up to 10 seconds on a physical device?
Upvotes: 0
Views: 354
Reputation: 563
Interestingly enough the problem only occurs in development. I tried to package the apk and manually install it on my phone through usb transfer, and the windows open instantly without any delay as seen before. (Same code and windows that took 10-15 seconds to open before). Also pubished the app on Google Play and t works fine. My best guess is that this has something to do with LiveView?:/ Either way, problem not solved, but problem no problem no more:)
Upvotes: 1
Reputation: 81
Is this happening the first load or after a few opens?
A couple things I noticed:
There is no cleanup / onClose code so your windows will sit in memory completely active and listening for events.
You are setting the user details before the window has even loaded, this should really be done once the window has loaded using the onOpen event.
Give that a try and see if it speeds up, the only the other thing to check (especially for older devices) is to enable large heap in the ti.xml
Upvotes: 1