标签  ”adb shell“  下的文章

Android平台“后台进程”的理解

    后台进程,应该有两种理解,一种用户的理解,一种是开发的理解。
    区别在于,对用户而言,所有在运行又看不见(界面)的进程都视为后台进程;而对于开发而言,后台进程只有一种,那就是调用了onStop()方法的进程。说这里不得不提一个Processes的生命周期,一个Android进程,一般分以下几种生命形态:
  1. Foreground process
  2. Visible process
  3. Service process
  4. Background process
  5. Empty process
这里面的第4类,就是开发级别的后台进程。

Background process官方说明

A process holding an activity that's not currently visible to the user (the activity's onStop() method has been called). These processes have no direct impact on the user experience, and the system can kill them at any time to reclaim memory for a foreground, visible, or service process. Usually there are many background processes running, so they are kept in an LRU (least recently used) list to ensure that the process with the activity that was most recently seen by the user is the last to be killed. If an activity implements its lifecycle methods correctly, and saves its current state, killing its process will not have a visible effect on the user experience, because when the user navigates back to the activity, the activity restores all of its visible state. See the Activities document for information about saving and restoring state.

    在adb shell am kill-all命令中解释为:Kill all background processes.
    这里指的就是Android 进程生命周期中的后台进程,所以在执行这个命令时,会发现手动切换到后台的进程 ,并不能被kill掉,原因就在此了,虽然被切换到后台,但在Android系统来看,还不算后台进程,在该进程调用onStop()后才会变成真正的Background process,kill-all命令才会对该进程生效。
    解释这个差异的目的在于明确用户与开发因角度不同,可能会在“需求分析”、“功能设计”等方面出现沟通理解上的存在漏洞。
参考文档:
http://developer.android.com/guide/components/processes-and-threads.html
http://developer.android.com/tools/help/shell.html

[Android]使用adb shell查看电池信息

如果想获取有关电池的一些信息,可以直接用adb命令来获取,方便自动化直接调用。
如下命令,通过cat可以获取全部Battery信息:
adb shell cat/sys/class/power_supply/battery/uevent
而且在/sys/class/power_supply/battery/目录中,通过cat可以直接获取相应的信息,如下: