简体   繁体   English

Sencha Touch 2 - Android性能

[英]Sencha Touch 2 - Android Performance

We are developing a Sencha Touch 2 application which makes use of Phonegap to be able to install it as an application and access the storage of a device. 我们正在开发Sencha Touch 2应用程序,该应用程序利用Phonegap将其作为应用程序安装并访问设备的存储。 This works really well on the iPad 2 and the iPad 3. However when we tried to run the application on an android device, the performance was very slow. 这在iPad 2和iPad 3上运行得非常好。但是当我们尝试在Android设备上运行应用程序时,性能非常慢。 The main elements which slowed down the system were lists and carousels. 减慢系统速度的主要因素是列表和轮播。 When we tried to test the same application through the chrome browser, the performance was on-par with that of the iPad. 当我们尝试通过Chrome浏览器测试相同的应用程序时,性能与iPad的性能相当。

Do you have any suggestions on what we can do to improve the performance on android, maybe even ditching Phonegap for something which works better. 你有什么建议我们可以做些什么来提高android的性能,甚至可能放弃Phonegap以获得更好的效果。 Or if we can force phonegap to run as a chrome browser. 或者,如果我们可以强制phonegap作为Chrome浏览器运行。

Thank you for your time & help. 感谢您的时间和帮助。

The problem you have here is that the Android browser does not use graphics hardware acceleration. 你在这里遇到的问题是Android浏览器不使用图形硬件加速。 This means that the standard tricks that Sencha (and other HTML5 libraries such as jQueryMobile, iScroll etc...) use to provide good scrolling performance, such as CSS 3D transforms to cause a your list to be rendered in a separate layer, which can then be translated in hardware, will not work on Android. 这意味着Sencha(以及其他HTML5库,如jQueryMobile,iScroll等......)用来提供良好的滚动性能的标准技巧,例如CSS 3D转换,使您的列表在单独的层中呈现,这可以然后在硬件上翻译,将无法在Android上运行。 Instead, list scroll will be performed entirely in software, which is going to be slow! 相反,列表滚动将完全在软件中执行,这将是缓慢的!

The Chrome browser, does however provide GPU acceleration. 然而,Chrome浏览器确实提供了GPU加速功能。 The Android device is more than capable of delivering a good HTML5 experience, it is simply that the standard browser does not take advantage of GPU hardware yet. Android设备能够提供良好的HTML5体验,只是标准浏览器还没有利用GPU硬件。

Unless you can force your end users to use Chrome (which I doubt), the only option is to degrade user experience, and deliver a slightly simpler UI for Android users. 除非您可以强制最终用户使用Chrome(我怀疑),否则唯一的选择就是降低用户体验,并为Android用户提供稍微简单的用户界面。

For further details, see "IMPROVING THE PERFORMANCE OF YOUR HTML5 APP" 有关详细信息,请参阅“提高HTML5应用程序的性能”

尝试在AndroidManifest.xml中设置此标志:android:hardwareAccelerated =“true”

Update: Having now worked with ST2 more longer now the performance challenges on Android are just something you have to accept. 更新:现在与ST2合作的时间越来越长,Android上的性能挑战只是你必须接受的。 There are many things you can do to avoid performance issues such as reduce listeners and events, keep your DOM light (below 2000 nodes) and generally avoid any CSS3 transformations and effects (these in particular don't perform well on Android) 您可以采取许多措施来避免性能问题,例如减少侦听器和事件,保持DOM轻量级(低于2000个节点)并且通常避免任何CSS3转换和效果(特别是在Android上表现不佳)

Another thing to consider is rather than using the built in WebView you could use the CrossWalk browser and embed this in APK. 另一件需要考虑的事情是,您可以使用CrossWalk浏览器并将其嵌入到APK中,而不是使用内置的WebView。

https://crosswalk-project.org https://crosswalk-project.org

It adds a little size to your APK (15-20MB), but it performs better than the built in WebView and brings stability and consistency to a very fragmented platform. 它为你的APK增加了一点大小(15-20MB),但它比内置的WebView表现更好,并为一个非常分散的平台带来稳定性和一致性。 Consider the reality that every WebView on Android depending on device, vendor and OS version may be different in small ways. 考虑到现实,Android上的每个WebView取决于设备,供应商和操作系统版本可能在很小的方面有所不同。 CrossWalk will allow you to have the exact same version across all Android 4.0+ devices and remove any device or vendor specific issues. CrossWalk将允许您在所有Android 4.0+设备上拥有完全相同的版本,并删除任何设备或供应商特定问题。

There is no silver bullet for performance on Android. 在Android上没有灵丹妙药的表现。 Graphics acceleration won't improve the perform of pure javascript execution or DOM manipulation. 图形加速不会改善纯javascript执行或DOM操作的执行。 If you want to understand why, then start here: 如果你想了解原因,那么从这里开始:

What's the difference between reflow and repaint? 回流和重绘之间有什么区别?

Older Answer (may still be valid): 较旧的答案(可能仍然有效):

For ICS and above the following setting on the webview will significantly improve rendering performance for Sencha Touch on Android: 对于ICS及更高版本,webview上的以下设置将显着提高Android上Sencha Touch的渲染性能:

mWebView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);

However in my experience this will introduce artifacts into CSS rendering depending on the device and platform variation. 但是根据我的经验,这将根据设备和平台变化将工件引入CSS渲染。 I haven't specifically found a reason for this and I don't expect Google will resolve it as the webview component will be getting replaced with a newer and better version in Android 4.4. 我没有特别找到理由,我不希望谷歌解决它,因为webview组件将被Android 4.4中更新更好的版本取代。

https://developers.google.com/chrome/mobile/docs/webview/overview https://developers.google.com/chrome/mobile/docs/webview/overview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM