adb 命令启动带参数的Activity

1.不带参数启动Activity

adb shell am start -n com.app.test/.MainActivity
adb shell am start com.app.test/.MainActivity

2.带参数的启动Activity

adb shell am start -n  com.app.test/.MainActivity --ei start_index 1

等同于Java代码:

  Intent intent= new Intent();
  intent.setComponent(new ComponentName("com.app.test", "com.app.test.MainActivity"));
  intent.putExtra("start_index", 1); 
  startActivity(intent);

3.指定Action

adb shell am start -a android.intent.action.MAIN -n  com.app.test/.MainActivity --ei start_index 1

4.指定category

adb shell am start -c android.intent.category.LAUNCHER -n  com.app.test/.MainActivity --ei start_index 1

5.同时指定action和category都可以

adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n  com.app.test/.MainActivity --ei start_index 1

对应命令的介绍

-a action;activity对应的action;
--es key stringValue; 传递 String 参数;
--ez key booleanValue; 传递 Boolean 参数;
--ei key intValue; 传递 int 参数;
--el key longValue; 传递 long 参数;
--ef key floatValue; 传递 float 参数;

参考文章:adb shell 命令启动带参数的Activity -125啦读书导航 - 阅读是一种生活方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值