这是我的manifest.xml
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:label="@string/app_name"
android:name="com.buttonpay.Login"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ButtonPayActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<!-- HomeTab Activity -->
<activity android:name="com.buttonpay.home.Utilities"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.Top_up"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.HomeScreen"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.MyAccount"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.TransactionHistory"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.TransactionDetailsActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.TransactionList"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name="com.buttonpay.home.BusinessSummaryActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<activity android:name=".home.MobileMoneyActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<!-- balance tab Activity -->
<activity android:name="com.buttonpay.balance.BalanceTab"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
/>
<!-- Favouritetab Activity -->
<activity android:name="com.buttonpay.favourite.FavouriteTab"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
/>
<!-- ComingSoon -->
<activity android:name="com.buttonpay.home.ComingSoon"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
<!-- Settings -->
<activity android:name="com.buttonpay.settings.SettingList"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"/>
</application>
答案 0 :(得分:3)
在清单中,将此设置在根活动上(这是第一个在您的应用中启动的活动,即ACTION_MAIN和CATEGORY_LAUNCHER):
android:clearTaskOnLaunch="true"
您不需要做任何其他事情。没有重写生命周期方法。
编辑经过一些实证实验后添加其他信息:
您需要确保 root活动始终位于任务的活动堆栈中才能使其正常工作。这意味着您无法在 root活动上调用finish()
,直到用户真正想要退出您的应用程序(即:当您在根活动中按下BACK键时强>)。
在您的示例中,您有LoginActivity,MenuActivity和DescriptionActivity,LoginActivity是 root活动。当LoginActivity启动MenuActivity时,它无法自行调用finish()
。在这种情况下,当用户在MenuActivity中按下BACK键时,它将返回LoginActivity。如果这不是您想要的,那么您需要在已启动MenuActivity的LoginActivity中设置一个标志,并且在调用onResume()
时,您可以检查该标志以确定您是否从MenuActivity返回并且在这种情况下,您可以立即致电finish()
。