I have implemented a splashcreen using a activity
that is inflated from its layout
with a centered image, but what I find that if it's the first time the app is installed, during loading / compilation it shows a blank screen, plus or minus 6 seconds, the second time you start the app starts directly with the SplashScreen.
Graphically so
The first time the app runs after installation or delete data from the setup menu
(click open app) ......................... (splashscreen) ------ (ready)
The second time the app opens
(click open app) (splashscreen) ------ (ready)
My question if there is any way to put a splashcreen during that pre-load period of Android.
Manifest.xml
<activity
android:name=".SplashActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme.SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Style AppTheme.SplashTheme
of the Theme that inherits the activity
<style name="AppTheme.SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
</style>
Layout XML splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorSplashScreen">
<LinearLayout
android:id="@+id/splashscreen"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:contentDescription="@string/about.alt_logo"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
SplashActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.LinearLayout;
/*
config_longAnimTime = 400
config_mediumAnimTime = 300
config_shortAnimTime = 150
*/
public class SplashActivity extends AppCompatActivity {
private String TAG = "SplashActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
final int SPLASH_DISPLAY_LENGTH = 1200;
final int SPLASH_DISPLAY_OFFSET = getResources().getInteger(android.R.integer.config_shortAnimTime);;
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Log.d(TAG, "onCreate() called with: " + "savedInstanceState = [" + savedInstanceState + "]");
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
final LinearLayout img = (LinearLayout) SplashActivity.this.findViewById(R.id.splashscreen);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
fadeOut.setAnimationListener(new Animation.AnimationListener()
{
public void onAnimationEnd(Animation animation)
{
img.setVisibility(View.GONE);
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Create an intent that will start the main activity.
Intent mainIntent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(mainIntent);
//Apply splash exit (fade out) and main entry (fade in) animation transitions.
overridePendingTransition(R.anim.zoom_enter, android.R.anim.fade_out);
//Finish splash activity so user cant go back to it.
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_OFFSET);
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationStart(Animation animation) {}
});
img.startAnimation(fadeOut);
Log.d(TAG, "finish SplashScreen: " + SPLASH_DISPLAY_LENGTH);
}
}, SPLASH_DISPLAY_LENGTH);
}
}
Update: The white screen is shown because it inherits from the light theme, because if I add the theme style, the screen is black.
<item name="android:background">#FF000000</item>
<item name="android:colorBackground">#FF000000</item>
I think the solution lies in implementing draw the icon by loading the theme before using an xml layout, open app --- > theme is applied ---- > Load layout in the interface.