Search code examples
androidandroid-intentsavestate

Open recent activity on app icon press , after pressing the home key of device


My Launcher class name is "SplashScreen". I have two Activities "MainActivity" and "MenuList". When user opens the app, SplashScreen Activity is started. Splash Screen Activity validates and starts MainActivity. User opens MenuList Activity by clicking on button in MainActivity Screen and clicks on home button in MenuList Activity. When user opens the app it should directly open MenuList Activity. I have made changes as mentioned in below link. It is working fine when user press home button in MainActivity. It is not working when user press home button in MenuList Activity. Please help me.

https://stackoverflow.com/a/20815679/1517280

ScreenFlow: SplashScreen -> MainActivity -> MenuList

Manifest code:

 <activity
            android:name=".SplashScreenActivity"
            android:clearTaskOnLaunch="true"
            android:launchMode="singleTask"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<activity
            android:name=".MainActivity"
            android:windowSoftInputMode="adjustResize|stateHidden"
            android:screenOrientation="portrait" />


<activity
            android:name=".MenuList"
            android:windowSoftInputMode="adjustResize|stateHidden"
            android:screenOrientation="portrait" />

Solution

  • Remove android:clearTaskOnLaunch="true" from SplashActivity's element.

    In fact, this doesn't work for your MainActivity either - since this flag is set, every time you get back to your application, the task's stack is being cleared and SplashActivity is being launched.