Activity四种启动模式

实验步骤:

第一步:实验前准备,相关配置文件以及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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值