Android_Intent的使用方法

Intent可以在2个activity之间传递参数。

1.简单数据的传递

currentActivity.java中的部分代码

Intent intent = new Intent(CurrentActivity.this, targetActivity.class);
			Bundle bundle = new Bundle();
			bundle.putDouble("num1", num1);
			bundle.putDouble("num2", num2);
			bundle.putDouble("num3", num3);
			bundle.putString("sign", sign);
			
			intent.putExtras(bundle);
			startActivity(intent);

调用startActivity方法时,开始跳转activity

secondActivity.java中的部分代码

Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		Double num1 = bundle.getDouble("num1");
		Double num2 = bundle.getDouble("num2");
		Double num3 = bundle.getDouble("num3");
		String sign = bundle.getString("sign");

2.传递对象

currentActivity.java中的部分代码

//封装对象(对象已实现序列化)
			Person person = new Person("Raise", "male", 23);
			Intent intent = new Intent(CounterActivity.this, CounterSecond.class);
			Bundle bundle = new Bundle();
			//存放序列化对象
			bundle.putSerializable("person", person);
			intent.putExtras(bundle);
			startActivity(intent);

调用startActivity方法时,开始跳转activity

secondActivity.java中的部分代码

//获取bundle对象
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		Person person = (Person) bundle.getSerializable("person");


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值