Intent

一、Intent的4种常用模式

1.

Intent intent=new Intent(this,NewActivity.class);

startActivity (intent)

2.

Intent intent =new Intent();

ComponentName cn=new ComponentName(this,NewActivity,class);

intent.setComponent(cn);

startActivity (intent);

3.

Intent intent =new Intent();

intent.setClass(this,NewActivity.class);

startActivity (intent);

4.

Intent intent =new Intent();

intent.setClass(getBaseContext(),NewActivity.class);

startActivity (intent);

二、Intent传递数据

1.

发起方:

Intent intent=new Intent(MainActivity.this, Initent.class);
intent.putExtra("a", "你好");
intent.putExtra("b", 1);

startActivity (intent);

接收方:

Intent intent=getIntent();
String s=intent.getStringExtra("a");

int z=intent.getIntExtra("b", 0);

2.

发起方:

Intent intent=new Intent(MainActivity.this, Initent.class);

Bundle bundle=new Bundle();
bundle.putString("c", "你也好");
bundle.putInt("d", 2);
bundle.putFloat("e", 12.5f);
intent.putExtras(bundle);
startActivity(intent);

接收方:

Bundle bundle=intent.getExtras();
String k=bundle.getString("c");
int v=bundle.getInt("d");
float f=bundle.getFloat("e");

三、Intention调用系统内部活动

打电话:

startActivity(new Intent(Intent.ACTION_CALL,Uri.parse("tel://10010")));

查看地图:

Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("geo:47.231810,-53.519061"));
startActivity(intent);

浏览网页:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com")));

播放音乐:

Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file:///mnt/sdcard/test.mp3"), "audio/mp3");

startActivity(intent);


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值