Android knowledge 260 - am command

First, open Activity, services, broadcasting


1. Open Activity, services, broadcast basics

By adb shell, can use the activity manager (arm) tools to perform various system operations, such as opening a Action, Activity an open, a thread is forced to stop, and the like to modify properties of the screen device, adb shell command format is as follows:

am [subcommand] [options]

Commands List:

command Features Implementation
am start [options<INTENT> Start Activity startActivityAsUser
at the start service  <INTENT> Start Service start service
am stopservice <INTENT> Stop Service stop service
am broadcast <INTENT> Send broadcast broadcastIntent
am kill <PACKAGE> Kill background processes specified killBackgroundProcesses
am kill-all Kill all background processes killAllBackgroundProcesses
am force-stop <PACKAGE> Strong kill process forceStopPackage
am hang Jamming system hang
am restart Restart restart
am bug-report Create a bugreport requestBugReport
am dumpheap <pid<file> Heap information output process pid to file Dumfeap
am send-trim-memory <pid<level> Tightening process memory setProcessMemoryTrimLevel
am monitor monitor MyActivityController.run

        am real implementations in order Am.java , almost all the final call ActivityManagerServicethe corresponding methods to complete, am monitorexcept. For example, the command am start -a android.intent.action.VIEW -d http://gityuan.comto start the Acitivty final call is ActivityManagerService class startActivityAsUser () method to complete. Another example is am kill-alla command, the final implementation work by ActivityManagerService the killBackgroundProcesses () to complete the process.

Next, talk about [options] and  <INTENT> significance parameters and how to correct the value.

1)intent

        intent will be appreciated that different components of the media or the messenger communication;

        intent can start an Activity, you can also start a Service, good can initiate a broadcast Broadcast

        By intent, your program can be as Android or express a willingness request, Android will select the appropriate components to complete the request in accordance with the wishes of content

Intent

Explanation

Am parameters [options]

component Component Name format: package name / class name -n
action Intent to perform the action specified, such as call dial phone components -a
data_url It denotes the operation of data manipulation to be -d
category categary is a string that provides additional information about the type of component capable of processing the object Intent -c
extra Intent to pass additional data, the definition of the form of the Bundle, that some key-value pairs -e
mime_type MIME type -t
flags Various types of flag, many Android system is used to specify how to start activity, as well as how to deal with him after the start of the activity -f
package Package names -p

So (1) Call 10086

am start -a android.intent.action.CALL -d tel:10086

(2) Open sitewww.gityuan.com

am start -a android.intent.action.VIEW -d  http://gityuan.com

(3) Activity Start: start package name com.yuanhh.app, as the main Activity .MainActivity, and extra data "website" is a key, "yuanh.com" to value. By java code to perform this function, although not complex, but requires at least one android environment through adb manner requiring only adb window, enter the following command can be completed:

am start -n com.yuanhh.app/.MainActivity -es website gityuan.com

2) Start Activity   ??? following did not understand, and then to add other practical.

# Start interface 

adb shell am start [parameters] <INTENT>           

parameter

Explanation

-D Turn on debug mode
-W Wait for the completion of startup
--start-profile <file> Beginning analyzer and sends the results (File)
--sampling INTERVAL Sec: sample analysis using an interval
between the sample (using the -start-profiler)
-P <FILE> After the application is idle down, stop profile
-R COUNT Duplication of activities launched <count> times. Before each repetition, activities will end
-S Organize activities before the start of the target application
--opengl-trace Enable tracing OpenGL functions
[—user <USER_ID> | current] Specify which users run, if not specified, the current user

3) Starting and stopping services

 

#启动服务

adb shell am startservice [参数] <INTENT>

#停止服务

am stopservice [参数] <INTENT>

 

参数 说明
--user <USER_ID> | current 指定哪些用户运行,如果不指定则使用当前用户

4)启动广播

#启动广播

am broadcast [参数] <INTENT>
参数 说明
--user <USER_ID> | current 指定哪些用户运行,如果不指定则使用当前用户

 

 

二、内存与进程操作


1.内存操作

获取heap文件:adb shell am dumpheap [参数] <process>

参数 说明
--user <USER_ID> | current 指定哪些用户运行,如果不指定则使用当前用户
-n 获取native heap而不是managed heap

例如:

adb shell am dumpheap com.android.browser /data/local/tmp/test.hprof

#获取内存快照(后缀名必需为.hprof)

使用adb pull /data/local/tmp/test.hprof e:\命令将testr.hprof文件保存到电脑本地

使用命令:hprof-conv e:\test.hprof e:\test1.hprof进行文件转化

然后就可以使用mat工具对内存进行查看分析

2.进程操作

adb shell am force-stop [参数] <process>

#强制停止应用(process=包名)

adb shell am kill [参数] <process>

#停止后台单个进程

adb shell am kill-all

#停止后台所进程

 

三、调试相关操作


1.性能相关

截图来自极客学院

image

Traceview是android平台配备一个很好的性能分析的工具。它可以通过图形化的方式让我们了解我们要跟踪的程序的性能,并且能具体到method。

 

发布了112 篇原创文章 · 获赞 3 · 访问量 9715

Guess you like

Origin blog.csdn.net/yush34/article/details/104679356