android adb shell命令行启动Activity service broadcast

在Android开发中,为了方便测试某一个组件,会直接使用adb 命令行来实现,下面分享实现方法
一、adb启动Activity:
adb shell am start -n {包(package)名}/{包名}.{活动(activity)名称}
如:启动Activity
adb shell am start -n com.xinrui/com.android.xinrui.MainActivity

二、adb关闭Activity:
adb shell am force-stop {包(package)名}
如:关闭Activity
adb shell am force-stop com.xinrui

三、adb启动service:
adb shell am startservice -n {包(package)名}/{包名}.{服务(service)名称}
如:启动自己应用中一个service
adb shell am startservice -n com.xinrui/com.xinrui.maniservice

四、adb发送broadcast:
adb shell am broadcast -a <广播动作>
如:发送一个网络变化的广播
adb shell am broadcast -n com.xinrui -a android.net.conn.CONNECTIVITY_CHANGE

发布了262 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/baidu_41666295/article/details/105054608