Search code examples
androidsplash-screen

Splashscreen works imperfectly with Support Action Bar in Android


I have a support action bar app in Android with a drawer layout and also a splash screen for the app.

The issue is when I launch my app, the ActionBar flashes for a second before the splash screen.

How do I fix this?

Here is my code for the splash screen:

public class SplashScreen extends ActionBarActivity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getSupportActionBar().hide();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splash_activity);

        new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, ZMainActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}

Here is my manifest:

    <activity
        android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
        android:label="MeriMasjid.com"
        android:screenOrientation="portrait" >

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

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

    </activity>

Please note that I cannot use any theme for my activity since it is an app compat app.

SOLUTION :

converting ActionBarActivity to Activity for Splashscreen and Applying @android:style/Theme.NoTitleBar to its entry in Manifest worked


Solution

  • Just because you use AppCompat does not mean every activity needs to extends ActionBarActivity - only those that need an action bar should extend ActionBarActivity. For your splash screen, you can extend Activity (if you don't need any fragments) or FragmentActivity (if you do need fragments). In either case, you can then use styles such as @android:style/Theme.NoTitleBar without exceptions.