Reputation: 985
I am trying to implement a splash screen before the MainActivity but cannot get it working. I followed the instructions found here: https://www.bignerdranch.com/blog/splash-screens-the-right-way/. Currently nothing appears but a black delayed screen. Please tell me where I went wrong. Thanks.
public class Splash extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
finish();
}
}
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/colorAccent"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash"/>
</item>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
<activity android:name=".Splash"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 1
Views: 780
Reputation: 394
Simple, Uninstall & install the app again, you will get the splash screen. The problem is due to the instant run in Android Studio
To test, give a delay before starting the new activity:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity();
}
}, 100);
Upvotes: 2
Reputation: 4867
Below super.onCreate(savedInstanceState);
add
setContentView(R.layout.layout_name.xml);
Upvotes: 0