0

在物理設備(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秒鐘的物理設備?

+1

如果你只是打開窗口沒有代碼會發生什麼> ie註釋掉js文件? – Ray

回答

1

這是第一次加載還是在幾次打開後發生?

一對夫婦的事情,我注意到:

  1. 沒有清理/ OnClose中的代碼,以便您的窗口將完全在內存中活躍,監聽事件坐。

  2. 您正在窗口加載前設置用戶詳細信息,這應該在窗口使用onOpen事件加載後真正完成。

給一個嘗試,看看它是否加快,只有其他的事情來檢查(尤其是舊設備)是爲了使大型堆在ti.xml只有

+0

它剛剛發生在每個窗口的第一次加載。他們所有的連續開口幾乎立即加載。細化代碼和組件的窗口會加速第一次加載,所以我猜想我做錯了什麼。必須倒退找出我的猜測 –

1

有趣的問題發展中發生。我試圖打包APK並手動通過USB傳輸將其安裝在我的手機上,並且窗口立即打開,沒有任何延遲,如前所見。 (相同的代碼和窗口需要10-15秒才能打開)。 也在Google Play上發佈了該應用,並且工作正常。 我最好的猜測是,這與LiveView有什麼關係?:/無論哪種方式,問題沒有解決,但問題沒有問題沒有更多:)