Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 621
FaisalAhmed Avatar asked Aug 01 '26 16:08

FaisalAhmed


2 Answers

You have to finish SplashActivity.

Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
finish();
like image 86
Pavya Avatar answered Aug 04 '26 05:08

Pavya


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>
like image 36
Lalit Sharma Avatar answered Aug 04 '26 05:08

Lalit Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!