Android应用之间的跳转以及参数的传递

  1. /**
  2. * @param v 设置按钮点击事件
  3. */
  4. @Override
  5. public void onClick(View v) {
  6. super.onClick(v);
  7. switch (v.getId()) {
  8. case R.id.tv_content://跳转点击事件
  9. //ComponentName 做跳转,第一个参数传递是B应用的包名,第二个参数传递的是你所需要跳转到B应用的界面
  10. try {
  11. ComponentName componentName = new ComponentName("com.example.intentActivity2", "com.example.intentActivity2.SecondActivity");
  12. Intent intent = new Intent();
  13. // Intent intent = new Intent("chroya.foo");
  14. Bundle bundle = new Bundle();
  15. bundle.putString("args", "我就是跳转过来的");
  16. intent.putExtras(bundle);
  17. intent.setComponent(componentName);
  18. startActivity(intent);
  19. } catch (ActivityNotFoundException e) {
  20. //判断是否安装B应用,提供下载链接
  21. NameToast.show(mContext, "请下载----" + "com.example.intentActivity2");
  22. e.printStackTrace();
  23. }
  24. break;
  25. }
  26. }



  1. public class MainActivity extends Activity {
  2. private TextView tv_content;
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.main);
  7. this.tv_content = (TextView) this.findViewById(R.id.tv_content);
  8. Intent intent = getIntent();
  9. String value = intent.getStringExtra("args");
  10. ToastUtils.show(value);
  11. }
  12. }



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值