Android adb shell am start命令總結

1.adb shell am start [options] <INTENT>

作用:啓動一個activity   adb shell am start com.android.settings/com.android.settings.Settings(com.android.settings/.Settings)

舉例:adb shell am start -a com.e.uu.main1

舉例:adb shell am start -n com.android.settings/com.android.settings.Settings(com.android.settings/.Settings)

舉例:啓動MainActivity laucher

adb shell am start -n com.android.settings/.Settings

說明:[options]與<INTENT>參見 http://developer.android.com/tools/help/adb.html#am

注:在實際調試的時候發現,調用start -n 啓動activity時,必須有intent-filter(manifest.xml中的紅色與藍色activity);而startservice則不需要。

帶String參數的命令

 adb shell am start -n com.e.uu/.MainActivity1 -e abc hello

代碼中通過String value= getIntent().getStringExtra("abc")

 

2.adb shell am startservice [options] <INTENT>

作用:啓動一個service

 

舉例:adb shell am startservice -n com.e.uu/.CoreService -e key value

 

3.adb shell am force-stop <PACKAGE>

作用:強制關閉一個應用程序

舉例:adb shell am force-stop com.lt.test

 

4.adb shell am broadcast [options] <INTENT>

作用:發送一個廣播

舉例:adb shell am broadcast -a "action_finish" (發送一個廣播去關閉一個activity)

舉例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢復出廠設置的方法,會清除內存所有內容)

舉例:adb shell am broadcast -n com.lt.test/.MyBroadcast

 

adb shell am start -n 包名/包名+類名(-n 類名,-a action,-d date,-m MIME-TYPE,-c category,-e 擴展數據,等)。

添加網絡DialogActivity

adb shell am start -n com.android.settings/com.android.settings.wifi.WifiDialogActivity

 

 

5.性能分析之常用adb命令adb shell am start -W

格式爲adb shell am start -W 包名/全類名或叫activity名

該命令具體實現在/frameworks/base/cmds/am/src/com/android/commands/am/Am.java,原理是跨Binder調用ActivityManagerService.startActivityAndWait() 接口,其中返回數據分別調用對應

startTime:  調用startActivityAndWait()的時間點

endTime:   調用startActivityAndWait()函數調用返回的時間點

WaitTime:  調用startActivityAndWait()調用耗時。

再通過之間的計算得到。
 

查看頁面啓動時間:

以啓動camera爲例

C:\Users\Administrator>adb shell am start -W com.mediatek.camera/com.mediatek.camera.CameraLauncher
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mediatek.camera/.CameraLauncher }
Status: ok
Activity: com.mediatek.camera/.CameraLauncher
ThisTime: 1340
TotalTime: 1340
WaitTime: 1384
Complete

打印的結果爲

ThisTime  該activity啓動耗時

TotalTime  應用自身啓動耗時=ThisTime+應用application等資源啓動時間

WaitTime  系統啓動應用耗時=TotalTime+系統資源啓動時間

在測試該啓動時間時需要理解兩個概念

冷啓動:應用第一次啓動

熱啓動:按back按鍵後再啓動或非第一次啓動切沒有清除該應用後臺或緩存數據

 

上面的數據爲冷啓動打印的數據,下面運行熱啓動的測試結果:

C:\Users\Administrator>adb shell am start -W com.mediatek.camera/com.mediatek.camera.CameraLauncher
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mediatek.camera/.CameraLauncher }
Status: ok
Activity: com.mediatek.camera/.CameraLauncher
ThisTime: 544
TotalTime: 544
WaitTime: 579
Complete
 

發佈了26 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章