Search code examples
androidandroid-intentintentfilter

Main Activity and Splash Screen Priority Prblm


I have a problem with Main Activity and Splash Screen.There is intent filter both of them

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

When I remove intent-filter from MainActivity the app cannot open.What must I do ?


Solution

  • AndroidManifest.xml

            <activity
                android:name="com.example.SplashScreen"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>            
            <activity
                android:name="com.example.MainActivity"
                android:label="@string/app_name" >
            </activity>
    

    SplashScreen Class

    public class SplashScreen extends Activity {
        private static int SPLASH_TIME_OUT = 3000;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);
    
            new Handler().postDelayed(new Runnable() {    
                @Override
                public void run() {
                    Intent i = new Intent(SplashScreen.this, MainActivity.class);
                    startActivity(i);
                    finish();
                }
            }, SPLASH_TIME_OUT);
        }
    }
    

    Main Activity Class

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    }