Intent的用法总结

传值:

Intent intent=new Intent();
intent.putExtra("数据名称", "数据");
intent.setClass(context, 跳转的activity.class);
startActivity(intent);

取值:

Intent intent=getIntent();
String StringE=intent.getStringExtra("数据名称");


打开网页:

Uri uri = Uri.parse("http://www.google.com");
Intent it  = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it); 

拨打电话:

Uri uri =Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL,uri);  
startActivity(it);

调用发短信的程序:

Intent it = new Intent(Intent.ACTION_VIEW);   
it.putExtra("sms_body", "TheSMS text");   
it.setType("vnd.android-dir/mms-sms");   
startActivity(it);

activity  A:

Intent intent=new Intent();
intent.setClass(A.this, B.class);
Bundle bundle=new Bundle();
String str1="aaaaaa";
bundle.putString("str1", str1);
intent.putExtras(bundle);
startActivityForResult(intent, 0);//这里采用startActivityForResult来做跳转,此处的0为一个依据,可以写其他的值,但一定要>=0

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) { //resultCode为回传的标记,我在B中回传的是RESULT_OK
   case RESULT_OK:
    Bundle b=data.getExtras(); //data为B中回传的Intent
    String str=b.getString("str1");//str即为回传的值
    break;
default:
    break;
    }
}

activity B:

setResult(1, intent); //调用onActivityResult  要写在finish()之前




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值