Appcelerator在Android上缓慢打开Windows

时间:2016-11-21 23:25:06

标签: android titanium appcelerator appcelerator-titanium appcelerator-alloy

我在物理设备(三星Galaxy S4)上运行Alloy项目,在第一次打开的事件中,窗口的打开速度非常慢。例如,在点击按钮上打开一个窗口可能需要10秒钟,具体取决于"多少stuf"窗口包含。但我不认为我做了一些与众不同的事情,下面的示例窗口。 窗口打开一次然后关闭后,第二次几乎立即打开。因为它在某种程度上"在记忆中"。

示例窗口:

<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;
  }
});

窗口确实需要两个其他文件,它们只是Utility模块,其中&#34; arrowdb&#34;有依赖性,需要在片刻,ti.cloud和Q库,但我仍然不认为这么多代码需要在物理设备上花费10秒钟?

2 个答案:

答案 0 :(得分:1)

这是第一次加载还是几次开启后?

我注意到了几件事:

  1. 没有清理/ onClose代码,因此您的窗口将完全处于活动状态并监听事件。

  2. 您在窗口加载之前设置用户详细信息,一旦使用onOpen事件加载窗口,就应该这样做。

  3. 尝试一下,看看它是否加速,唯一要检查的另一件事(特别是对于旧设备)是在ti.xml中启用大堆

答案 1 :(得分:1)

有趣的是,这个问题只发生在开发中。我试图打包apk并通过usb传输手动安装在我的手机上,并且窗口立即打开,没有任何延迟,如前所示。 (相同的代码和窗口需要10-15秒才能打开)。 也在Google Play上发布应用程序并且工作正常。 我最好的猜测是,这与LiveView有关吗?:/无论哪种方式,问题都没有解决,但问题不再存在问题:)

相关问题