FaisalAhmed FaisalAhmed - 4 months ago 20
Android Question

Activity flow in android

Sorry if this question has been asked before . What I am trying to do is when app starts splash screen appear and after 3 second My

mainactivity
runs . but when I press back button it returns me again on splash screen . So my question is how can I control the flow of activity so that it should not come again to
splash screen
below is my

manifest file

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>


And if there are lots of activity and i want my mainactivity to be parent activity and if user is on parent activity and user press back then splash screen should not appear . Is there a way to do that through manifest

Answer

The Simplest solution is: set android:noHistory="true" in manifest.xml

<activity android:name=".SplashScreen"
          android:noHistory="true" 
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Comments