-2
package com.dswipu.dswipu;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Toast;

public class splash extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 5000;
    private UserSessionManager session;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {


        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getActionBar().hide();
        setContentView(R.layout.activity_splash);

          Utility ut = new Utility(this);
        if(!ut.checkInternet())
        {

            Toast.makeText(getApplicationContext(), "No internet connection",
                    Toast.LENGTH_LONG).show();

        }
        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
                session = new UserSessionManager(getApplicationContext());
                if (session.isUserLoggedIn()) {

                    Intent i = new Intent(getApplicationContext(), Home.class);
                    startActivity(i);

                } else {
                    Intent i = new Intent(splash.this, Auth.class);
                    startActivity(i);
                }
                // close this activity
                finish();

            }
        }, SPLASH_TIME_OUT);
    }

}

03-16 11:43:47.932 4037-4037/com.dswipu.dswipu E/AndroidRuntime: FATAL EXCEPTION: main Process: com.dswipu.dswipu, PID: 4037 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dswipu.dswipu/com.dswipu.dswipu.splash}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content at com.android.internal.policy.PhoneWindow.requestFeature(PhoneWindow.java:317) at com.dswipu.dswipu.splash.onCreate(splash.java:22) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  03-16 11:43:47.934 1685-2328/system_process W/ActivityManager: Force finishing activity com.dswipu.dswipu/.splash 03-16 11:43:48.237 1685-2328/system_process I/WindowManager: Screenshot max retries 4 of Token{e07b2da ActivityRecord{2395485 u0 com.dswipu.dswipu/.splash t17 f}} appWin=Window{8f28f3d u0 Starting com.dswipu.dswipu} drawState=4 03-16 11:43:48.268 2501-4094/com.google.android.gms D/DropBoxEntryAddedChimeraService: User is not opted-in to Usage & Diagnostics. 03-16 11:43:48.296 1685-2572/system_process I/OpenGLRenderer: Initialized EGL, version 1.4

1 Answers1

1

for AppCompatActivity requst feature should be called before super call to onCreate.

public class splash extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 5000;
    private UserSessionManager session;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {

        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        super.onCreate(savedInstanceState);
        getActionBar().hide();
        setContentView(R.layout.activity_splash);
.
.
.

   }
}

For making the activity full screen you can also add the following code to your 'styles' xml file, if it doesnt exist create it under values

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

in the manifest file then apply this theme to your activity:

<activity
        android:name=".ui.activity.SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppFullScreenTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
Harsh Ganatra
  • 411
  • 3
  • 8