实验步骤:
第一步:实验前准备,相关配置文件以及Activity的建立
(1)AndroidMainfest.xml配置文件其代码:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.bzu.intentflags">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity >
<activity android:name=".ThirdActivity"></activity>
</application>
</manifest>
(2)布局文件activity_first.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_first" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="cn.edu.bzu.intentflags.FirstActivity" >
<Button android:id="@+id/b1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第一个页面" android:onClick="click1" />
<Button android:id="@+id/b2" android:layout_below="@+id/b1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二个页面" android:onClick="click2" />
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第三个页面" android:onClick="click3" android:id="@+id/b3" android:layout_below="@+id/b2"/>
<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="第一个页面" android:layout_below="@+id/b3"/>
</RelativeLayout>
界面展示图:
布局文件activity_second.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_second" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.edu.bzu.intentflags.SecondActivity">
<Button android:id="@+id/b2" android:layout_below="@+id/b1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二个页面" android:onClick="click2" />
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第三个页面" android:onClick="click3" android:id="@+id/b3" android:layout_below="@+id/b2"/>
<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="第二个页面" android:layout_below="@+id/b3"/>
</RelativeLayout>
界面展示图:
布局文件activity_third.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_third" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.edu.bzu.intentflags.ThirdActivity">
<Button android:id="@+id/b2" android:layout_below="@+id/b1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二个页面" android:onClick="click2" />
<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="第三个页面" android:layout_below="@+id/b2"/>
</RelativeLayout>
界面展示图:
以上代码为standard启动模式下的源代码
singleTop启动模式需要设置页面二为singleTop
singleTask启动模式需要设置页面二为singleTask
singleInstance启动模式需要设置页面二为singleInstance