Reputation: 6345
We are using the splash screen to show the company logo every time user open the app. Currently, we are showing the splash screen for 3 Seconds.
Below is the code:
private static int SPLASH_TIME_OUT = 3000; // Delay of 3 Seconds
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
Intent i = new Intent(SplashScreenActivity.this, AnotheActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
But this splash screen duration is just randomly chosen within team. We kind-of know that Splash screen in general is not all that encouraged in Android app ecosystem, but since this is our app's need, hence it is implemented.
My Question: Is there any standard Android guideline/best practice for choosing the RIGHT splash screen duration time?
Upvotes: 6
Views: 19943
Reputation: 4584
A better option is to use a splash screen activity with a custom theme, that starts the main content activity. With this there is no need to use a timer, as it switches to main content when the app is ready, and in the meantime shows a picture that is inside the theme.
Here is tutorial how to do it - https://www.bignerdranch.com/blog/splash-screens-the-right-way/
Main parts from the tutorial:
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"> THEME HERE!!!
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
<style name="SplashTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/black"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo_image"/>
</item>
</layer-list>
It is even possible to add the style to the application, without a need to use a separate activity.
Upvotes: 9
Reputation: 6569
Splash screen it's bad practice, when it possible not to use it than please avoid using splash screen. You can read a some articles about this link1, link2.
But if need to show splash than use through creating a custom theme that overrides android:windowBackground
, then replacing that custom theme with your standard theme before calling super.onCreate()
. Here is tutorial of implementation and detailed description.
Assuming you have a theme called AppTheme, your launcher theme would be:
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
Then apply your theme to your activity in your AndroidManifest.xml using android:theme="@style/AppTheme.Launcher".
The easiest way to transition back to your normal theme is to call setTheme(R.style.AppTheme) before super.onCreate() and setContentView():
public class MyMainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.Theme_MyApp);
super.onCreate(savedInstanceState);
// ...
}
}
Upvotes: 2
Reputation: 1665
A community-accepted standard solution is using a launch theme.
Check out this post: http://saulmm.github.io/avoding-android-cold-starts
Upvotes: 0
Reputation: 2267
Google guidelines are pretty clear. Use splash screen only if you must. (If you don't have anything to show to user) It should be visible only until you have some data to show. If you go trough Google apps you will very rear see a splashscreen. There is much cleverer ways to brand your app. You can find more data here.
Upvotes: 1