<Android Programming Pushing the Limits> 读书笔记

来源:互联网 发布:玻璃杯 知乎 编辑:程序博客网 时间:2024/06/06 01:09

The ADB Tool

常用adb命令:
  • adb devices - 列出所有已连接的设备和模拟器
  • adb push <local> <remote> - 从电脑copy文件到android机器
  • adb pull <remote> <local> - 从android机器copy文件到电脑
Logcat过滤:
通常,可以为应用的每个类都定义一个单独的TAG,这样可以在log中用于过滤,例如:
private static final String TAG = "MyActivity";
Log.d(TAG, "Current value of moderation: " + moderation)
之后,可以在adb中进行过滤log,命令:adb logcat MyActivity.* *:s

通过WIFI连接ADB:
通过 adb tcpip <port> 和 adb connect <ip> 两个命令就可以进行无线设备连接,但是这里有个问题,连接不一定对所有设备都可以行,以及效率相对于USB会非常差。

在Android设备上执行命令:
通过调用adb shell命令,可以直接登录android机器上的shell命令行进行操作,其中am和pm命令是其中两个在开发中尤其有用的命令,通过他们可以与Application manager和Package manager打交道。例如,如果你有一个可以通过Intent启动的Service,就可以通过am命令进行测试:adb shell am startservice -a <intent action>。同样,不仅仅可以启动service,还可以启动一个Activity或者发送一个广播intent。使用"adb shell am"命令可以列出所有有用的命令。对于pm命令,Package Manager可以与已安装的所有应用进行交互,比如list/install/unstall/获取权限和特性。

自动化测试:
adb shell monkey -p <package name> <event count>


Efficient Java Code for Android

There are serval differences between JavaSE and Dalvik Java, mostly regrading the virtual machine. Although JavaSE uses a stack machine design, Dalvik was designed as register-based machine.The Android SDK has a tool called dx that converts the JavaSE stack machine byte-code to Dalvik register-based machine byte-code. Up until Android version 2.2 , the Dalvik VM was purely interpreted. With the Froyo version of Android came the introduction of a JIT compiler(Just In Time), something that Java SE had benefitted from for a  long time. JIT compilation, also known as dynamic translation, takes the byte-code and translates it into native code prior to execution.
上面的意思,根据我的理解是,原来Android使用的Java仅仅是语法和Java SE相同,但是具体执行的时候完全不一致,并且Dalvik 也就是Android Java虚拟机的效率相对Java SE并不高,虽然2.2之后引入了一个新技术,但是相对来说,虚拟机的执行效率还是不如Java那么吸引人。

Another difference between the Java SE VM and the Dalvik VM is that the latter is optimized for running in multiple instances on the same machine. This is handled by a process started at boot called zygote that creates the first Dalvik instance that will be the parent of all other instances. 
这段说Android应用所有的进程其实来源于一个进程,这个进程叫zygote。

In addition to running with a different virtual machine than the one Java SE uses, Android has a different implementation of the APIs. All the APIs in Android that belong to the java or javax packages come from Apache Harmony, an open-source project aiming for reimplementation of the Java SE stack.(The Apache Harmony project has been retired since November 2011 and is no longer being actively developed).
这段比较有意思,一直我意味Android开发中用到的Java其实严格来说并非Java,而且更神奇的是这个项目在2011年sun被收购之后已经停止开发了,google估计会非常蛋疼的

0 0
原创粉丝点击