意图:Intent用于激活组件和携带数据,用来协助完成android中歌组件之间的通讯。
1.显示意图必须要知道被激活组件的具体信息(包名.组件名.组件的class);
2.隐示意图,没有明确指定组件名的Intent为隐式意图,只需要知道跳转组件的动作,数据,或者类型,系统根据提供的数据自动匹配合适的组件,就可以激活对应的组件
显示意图:
/**
* 方法一
*/
Intent intent1 = new Intent();
// 1.是当前的包名,2跳转activity的类名,一定要加上包名
intent1.setClassName("com.itcast.intent", "com.itcast.intent.DemoActivity");
// startActivity(intent1);
/**
* 方法二
*/
Intent intent2 = new Intent(this, DemoActivity.class);
// startActivity(intent2);
/**
* 方法三
*/
Intent intent3 = new Intent();
ComponentName component = new ComponentName("com.itcast.intent", "com.itcast.intent.DemoActivity");
intent3.setComponent(component);
// startActivity(intent3);
/**
* 上面三种方法要求必须知道被激活组件的包和class,称为显示意图
*/
隐示意图:
隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件
Intent intent=new Intent();
//意图用于激活一个界面
//隐示意图
//描述动作的行为
intent.setAction(Intent.ACTION_VIEW);//描述执行的动作
intent.setData(Uri.parse("http://www.baidu.com"));//数据
startActivity(intent);
android Intent 显示和隐示意图
最新推荐文章于 2023-07-23 16:50:41 发布