1.显示意图开启一个新的界面
1:创建一个新的layout界面
2.新建SecondActivity类 extends Activity
public
class
SecondActivity
extends
Activity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.
second
);
}
}
3.配置AndroidManifest.xml
在
<
application> 节点下添加:
<
activity
android:name
=
"com.itheima.intent.SecondActivity"
>
</
activity
>
4.创建显式意图
/**
* 开启一个新的界面
*/
public
void
click(View view){
//创建intent
//Intent intent=new Intent();
//intent.setClassName(getApplicationContext(), "com.itheima.intent.SecondActivity");
Intent intent=
new
Intent(
this
,SecondActivity.
class
);
startActivity(intent);
}
---------------------------------------------------------------------------------------------------------------
2.隐式意图开启一个新的界面
<!-- 新的界面的activity配置 -->
<
activity
android:name
=
"com.itheima.intent.SecondActivity"
>
<
intent-filter
>
<
action
android:name
=
"com.itheima.second"
></
action
>
<!--可以任意命名 -->
<
data
android:mimeType
=
"text/plain"
/>
<
category
android:name
=
"android.intent.category.DEFAULT"
/>
</
intent-filter
>
</
activity
>
/**
* 开启一个新的界面
*/
public
void
click(View view){
//创建intent
Intent intent=
new
Intent();
intent.setAction(
"com.itheima.second"
);
intent.setType(
"text/plain"
);
startActivity(intent);
}