本文介绍了如何显示启动画面,只有当应用程序启动"新鲜QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的应用程序生命周期中显示启动画面只有一次。这里是我的code:

I want to show the splash screen only once during the Application life cycle. Here is my code:

SplashScreenActivity.java:

SplashScreenActivity.java:

final int welcomeScreenDisplay = 3000;

Thread welcomeThread = new Thread() {

    int wait = 0;

    @Override
    public void run() {
        try {
            super.run();

            while (wait < welcomeScreenDisplay) {
                sleep(1000);
                wait += 1000;
            }
        } catch (Exception e) {
            System.out.println("EXc=" + e);
        } finally {

            // Start other Activity
            startActivity(new Intent(SplashScreenActivity.this,
                    MainActiviey.class));
            finish();
        }
    }
};
welcomeThread.start();

清单:

    <activity android:name=".SplashScreenActivity" android:label="test"
    android:noHistory="true"
        android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|keyboard">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActiviey" android:label="test"
         android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden|keyboard">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

问题是如果我preSS硬件HOME钮隐藏应用程序,并在应用程序列表中再次打开该应用程序。它会再次出现闪屏(而不是显示 MainActivity )。
是否有可能显示启动画面,只有当应用程序启动新鲜(在onresume不显示())?谢谢!

The problem is if I press the hardware HOME botton to hide the app and open the App again at the application list. It will show the splash screen again (instead of showing the MainActivity).Is it possible to show splash screen only when the app starts "fresh" (not show at onresume() )? Thanks!

推荐答案

是的,这是可能的。使用来存储一个标志,这将表明,您的溅已经显示。检查它在的onCreate()方法闪屏的,如果它是present,启动下一个活动。

Yes, it's possible. Use SharedPreferences to store a flag, that would indicate that your splash has already been shown. Check it in onCreate() method of your splash screen and if it is present, launch the next activity.

这篇关于如何显示启动画面,只有当应用程序启动&QUOT;新鲜QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 23:48