Kill activity when it comes to foreground
android, android-activity, android-intent
Solution
In the manifest, set this on your root activity (that is the first one that gets launched in your application, the one with ACTION_MAIN and CATEGORY_LAUNCHER):
android:clearTaskOnLaunch="true"
You don't need to do anything else. No overriding of lifecycle methods.
EDIT Add additional information after some empirical experimentation:
You need to make sure that your root activity is always in the task's activity stack to make this work. This means that you can't call `finish()` on the root activity until the user actually wants to quit your application (ie: when he presses the BACK key when in your root activity).
In your example you have a LoginActivity, MenuActivity and DescriptionActivity and the LoginActivity is the root activity. When the LoginActivity launches the MenuActivity it cannot call `finish()` on itself. In this case, when the user presses the BACK key while in the MenuActivity, it will return to the LoginActivity. If this isn't what you want then you need to set a flag in the LoginActivity that you've already launched the MenuActivity and when `onResume()` is called you can check that flag to determine if you are returning from the MenuActivity and in that case you can just immediately call `finish()`.
Problem
i m writing an application n stuckup with one problem.I have three activity A,B and C. when i goes from activty A to B and B to C and if i press menu button on device.my application goes into background state. when i reopen application it shows Activity C. I want when i reopen my application it should shows Activity A instead of any other activity from Activity stack. I have gone through some activity lifecycle method and try to override it.i have override onStart() ,onPause() method and finsh activity C as well as Activity B and the problem i m facing is when i go from Activity C to activity D activity C finish all background activity n m not able to go back to acitvity C on finish of Activity D. Can anyone help me how to show specific acitivity on resume of application?? thansks in advance. here is my 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> ```