本文参考《第一行代码》
一、显式方式
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
startActivity(intent);
关于Intent函数:
Intent(Context packageContext,Class<?>cls);
第一个参数packageContext:启动活动的上下文,即哪个活动中需要启动另一个活动。
第二个cls:指定想要启动的目标活动。
二、隐式方式
隐式是指不指定启动哪个活动,而是通过一系列标签来启动活动,如:action和category等。
如果action对应的category为默认的时候:
Intent intent = new Intent("动作");
startActivity(intent);
category会被自动加载到Intent中。
注:此时category为"android.intent.category.DEFAULT"
故称为隐式方式。
如果action对应的category非默认的时候:
Intent intent = new Intent("动作");
intent.addCategory("com.example.activitytest.MY_CATEGORY");
startActivity(intent);
关于Intent():
在源代码中我们可以找到
public Intent(String action) {
setAction(action);
}