在物理設備(Samsung Galaxy S4)上運行Alloy項目時,第一次打開窗口時窗口的打開速度非常慢。例如,打開一個按鈕點擊窗口可能需要長達10秒,具體取決於窗口包含多少stuf。但我不認爲我在做任何不尋常的事情,儘管如此,下面的示例窗口。 窗戶打開一次後關閉,第二次幾乎立即打開。因爲它在某種程度上「在記憶中」。Appcelerator在Android上緩慢打開窗口
實例窗口:
<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;
}
});
窗口確實需要另外兩個文件,這都只是工具模塊,其中 「arrowdb」 有依賴關係,並在需要的時刻,ti.cloud和Q庫,但我不認爲這樣的很多代碼需要10秒鐘的物理設備?
如果你只是打開窗口沒有代碼會發生什麼> ie註釋掉js文件? – Ray