Delay in starting the main activity

when I start my activity, I notice a slight delay. I click on the icon of my application, and the home screen remains on the screen for about 1-1.5 seconds before my activity is shown.

My activity onCreate method takes about 800 ms.

I also noticed that the installation android:screenOrientation="landscape"also adds a noticeable delay, even when I use test activity with an empty layout.

Is there any way to get rid of this delay or at least show a black screen while loading the user interface?

Edited: see code for test activity below. In my real life, there are a bunch of different downloads, including GUI elements and engine logic, sound, etc. The real problem is that the delay is visible even when using this small test activity.


Code for test activity:

public class TestActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set full screen mode and disable
        // the keyguard (lockscreen)
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN  
                             | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
                             | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                             | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.main);
    }
}

XML format:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"  >
</FrameLayout>

manifest:

<activity
    android:name=".TestActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/app_name"
    android:screenOrientation="landscape"
    android:windowSoftInputMode="stateAlwaysHidden|adjustPan" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
+3
source share
3 answers

you can set the default activity to an almost empty activity, which no more than shows the background and starts your real activity .. like a screensaver

+2
source

As Drake said, the screensaver works very well. Here is a link to a similar question that shows how to create one through AsyncTask: Android SplashScreen

0
source

Ans Drake , - , . , , UX. , , setContentView, .

java, onCreate . .

, , .

, :

<activity
        android:name=".main.activities.SplashScreen"
        android:theme="@style/Splash"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

:

<style name="Splash" parent="@style/Theme.AppCompat.Light">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowNoTitle">true</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimaryDark">@color/green_09</item>
    <item name="colorPrimary">@color/green_09</item>
    <item name="windowActionBar">false</item>
</style>

A splash of the resource that contains the bitmap resource, I have to tweak it a bit so that it looks perfectly unstretched and in the center:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:antialias="true"
    android:dither="true"
    android:gravity="fill"
    android:src="@drawable/splash_screen" />
0
source

All Articles