Month: August 2013

Android Runtime 资源回收的单位是Activity还是Process ?

Android Runtime要回收资源时,倒底是弄掉可回收的Activity, 还是直接杀掉Process ? According to Google’s Documents: 引用 If an activity in the foreground of the screen (at the top of the stack), it is active or running. If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it …

Android Runtime 资源回收的单位是Activity还是Process ? Read More »

为什么在调用栈的较深处抛异常会导致性能问题 ?

为什么在调用栈的较深处抛异常会导致性能问题 ? 这是因为 构建Exception对象时会去取一下当前调用栈的快照(Throwable.fillInStackTrace()),这个操作比较耗时。 栈越深,操作就越耗时。 怎么解决这个问题? 1. 避免滥用Exception作为Flow-Control的工具。 比如判断类型时可以用 instanceof ,而不必强转+捕捉ClassCastException. 2. 重用Exception对象。 这样总体上只需要取一次栈的快照。 3. 覆盖fillInStackTrace()方法,使它变成空方法;也就是说, 不生成快照。

Android进程的优先级

Android Runtime在资源紧张时会杀掉一些进程。 优先级低的进程就被首先杀掉。 进程的优先级取决于它们的状态,优先级从高到低排列是: 1. Foreground process   — 正在与用户交互 2. Visible process      — 可见,但不能交互,比如进程里的Activity被部分遮挡 3. Service process      4. Background process   — 无交互、不可见、也不是Service 5. Empty process        — 进程被回收后会保存在内存中,作为缓存(下次启动时可以快一点)

html5到底支持哪些新的交互事件,可以调用哪些硬件?

html5到底支持哪些新的交互事件,可以调用哪些硬件? 找了半天,没找到一个列出全部特性的单一网站, 但你可以参考浏览器、JS框架获得这些信息: JQuery Mobile支持的Event列表: http://api.jquerymobile.com/category/events/ Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/WebAPI,可访问的硬件信息,以及其他浏览器是否支持这些访问。 Sencha Touch支持的Native访问: http://docs-origin.sencha.com/touch/2.2.1/#!/api 看最下面

Android UI的一些基本概念

Activity:  相当于窗体 View:  相当于控件. View使用了Composite模式, 所以 ViewGroup – 用来组合View的东西,也是一种View. 比如Layout本身也是View. Fragment: 可以视为一种特殊的Activity, 但它只能被包含在其他Activity中。 相当于PHP/JSP中被<inclue>的page.

android使用的java语言规范的版本跟原生Java的版本没有对应关系

android 4所支持的JAVA语法是否兼容JAVA6的语法 ?  只能说大体上是,但没有明确说法;事实上,两者的版本没有对应关系。 说得更极端一点,android目前没有为自己所用的java语言提供版本机制: 引用 "java.version" property returns 0 because it is not used on Android, "java.specification.version" invariably returns 0.9 independently of the version of Android used, "java.class.version" invariably returns 50 independently of the version of Android used, 参考: http://en.wikipedia.org/wiki/Comparison_of_Java_and_Android_API#System_properties