1.显式意图
public
class
MainActivity
extends
Activity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.
activity_main
);
}
//显式意图 必须指定动作的执行者
public
void
click(View view){
Intent intent=
new
Intent();
//指定要激活组件的包名和类名
intent.setClassName(
"com.android.calculator2"
,
"com.android.calculator2.Calculator"
);
startActivity(intent);
}
}
2.隐式意图
public
class
MainActivity
extends
Activity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.
activity_main
);
}
//隐式意图: 只需要制定动作
public
void
click(View view){
Intent intent=
new
Intent();
intent.setAction(intent.
ACTION_VIEW
);
//设置动作
intent.setData(Uri. parse(
"http://wwww.baidu.com"
));
startActivity(intent);
}
}