zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

android adb shell命令行启动Activity service broadcast

Android命令行adbshell 启动 Service Activity Broadcast
2023-09-14 09:05:09 时间

在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