Activity启动模式系列(一)singleInstance启动模式

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name=".Test1"  android:launchMode="singleInstance"/>
<activity android:name=".Test2"  android:launchMode="singleInstance"/>

1.MainActivity启动Test1 Test1启动Test2

2.Test2启动Test1,Test1再启动Test2

如此循环往复10次,

问:有多少个栈?里面有多少个Test1,Test2?

答:本app共三个栈,MainActivity一个,Test1一个,Test2一个,每一个栈里面都只有一个实例

---------------------------------------------------------------------------------------------------------------------------------------

从上面的例子可以看出,无论多少字,singleInstance都是只有一个实例

---

singleInstance  字面意思是单例,其实际含义基本和字面意思相同。

其使用场景是:假设程序中有一个活动是允许其他程序调用的,如果想使其他程序和这个程序共享这个活动的实例。则可以使用singleInstance.

例如:

呼叫来电界面:

(7.1源码)

      <!-- Main in-call UI activity.  This is never launched directly
             from outside the phone app; instead, it's either launched by
             the OutgoingCallBroadcaster (for outgoing calls), or as the
             fullScreenIntent of a notification (for incoming calls.) -->
        <activity android:name="com.android.incallui.InCallActivity"
                  android:theme="@style/Theme.InCallScreen"
                  android:label="@string/phoneAppLabel"
                  android:excludeFromRecents="true"
                  android:launchMode="singleInstance"
                  android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden"
                  android:exported="false"
                  android:screenOrientation="nosensor"
                  android:directBootAware="true"
                  android:resizeableActivity="true">
        </activity>

闹铃提醒界面

(7.1源码)

 <!-- This activity displays only the timers that have expired with only a reset button
         present. This makes the activity appropriate for display above the lock screen so that
         users have the limited ability to silence expired timers but nothing else. -->
        <activity android:name=".timer.ExpiredTimersActivity"
                android:excludeFromRecents="true"
                android:theme="@style/ExpiredTimersActivityTheme"
                android:launchMode="singleInstance"
                android:showOnLockScreen="true"
                android:taskAffinity=""
                android:configChanges="screenSize|keyboardHidden|keyboard|navigation"/>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值