CodeName One 应用程序的 HTC 性能问题?

HTC Preformance Issue with CodeNameOne App?

我使用 codenameone 创建了一个应用程序,当我在各种设备上进行测试时 [在不同类型上都很好,在 Apple 上试用过,Android], 我注意到 HTC 设备上的一个问题,浏览屏幕或在屏幕之间移动时出现一些意外的缓慢

您能否就一些可以解决此问题的构建参数或找出延迟源的任何类型的方法提出建议??

我所做的是拆分对话框和表单的创建和使用。如果您不使用 GUIBuilder(无论新旧),那么您也可以试试这个。它对我解决性能问题有很大帮助,这是一个例子:

首先会有一个LoginForm:

class Login extends Form {
   MainForm f; //do not initiate

   public Login () {
     this.setLayout (BoxLayout.y());
     this.add(new Label("username:").add(new TextField("","username"));
     this.add(new Label("pw:").add(new TextField("","password"));
     Button login = new Button ("Login");
     login.addActionListener(e -> {
        f.provideParameters(providedName,providedPw);
        f.show();
     }
     Display.getInstance().scheduleBackgroundTask(new Runnable {
       public void run() {
         //initiation in the background
         f = new MainForm ();
       }
     );
}

然后是主窗体

class MainForm extends Form {

  private Label welcomeLbl;

  public MainForm () {
    //here you dont have the username
    //but running it in the background creates all the components, so...
    welcomeLbl = new Label();
  }

  public void provideParameters (String name, String pw) {
    //...they are ready to use here!
    this.welcomeLbl.setText("Welcome " + name);
  }
}

通过这种方式,我体验到了巨大的性能提升,因为复杂对象的构建被外包给了后台而不是前台。

注意这只是一个例子。对象越复杂,性能提升就越高。

Note2 此代码未经测试。这只是为了澄清目的