There is another solution for this, you can create another class for SplashScreen and make SplashScreen as your Launcher activity, but not MainActivity. Like this:
<activity android:name=".SplashScreen" android:label="@string/title_activity_splash_screen" android:screenOrientation="portrait" android:theme="@style/AppTheme.NoActionBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme" > </activity>
And thn in SplashSacreen.java, you write the code like this:
public class SplashScreen extends AppCompatActivity { private static int SPLASH_TIME_OUT = 3000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen); new Handler().postDelayed(new Runnable() { @Override public void run() {
Thn after in SplashScreen.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_red_dark" > <ImageView android:id="@+id/imgLogo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/comp_logo" />
And then check it out
source share