Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用定时器显示屏幕_Java - Fatal编程技术网

Java 用定时器显示屏幕

Java 用定时器显示屏幕,java,Java,我想先在我的应用程序上显示一个闪屏几秒钟,然后用java中的定时器加载我的所有线程数据,然后我该怎么做。将闪屏活动添加到项目中。。。 现在将SplashScree.java文件代码替换为: package samples.splash.screen; import android.app.Activity; import android.os.Bundle; import android.os.Handler; /** * Splash sc

我想先在我的应用程序上显示一个闪屏几秒钟,然后用java中的定时器加载我的所有线程数据,然后我该怎么做。

将闪屏活动添加到项目中。。。 现在将SplashScree.java文件代码替换为:

    package samples.splash.screen;

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;

    /**
     * Splash screen activity
     *
     * @author Catalin Prata
     */
    public class SplashScreen extends Activity {

        // used to know if the back button was pressed in the splash screen activity and avoid opening the next activity
        private boolean mIsBackButtonPressed;
        private static final int SPLASH_DURATION = 2000; // 2 seconds


        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.splash_screen);

            Handler handler = new Handler();

            // run a thread after 2 seconds to start the home screen
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {

                    // make sure we close the splash screen so the user won't come back when it presses back key

                    finish();

                    if (!mIsBackButtonPressed) {
                        // start the home screen if the back button wasn't pressed already 
                        Intent intent = new Intent(SplashScreen.this, Home.class);
                        SplashScreen.this.startActivity(intent);
                   }

                }

            }, SPLASH_DURATION); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called

        }

        @Override
       public void onBackPressed() {

            // set the flag to true so the next activity won't start up
            mIsBackButtonPressed = true;
            super.onBackPressed();

        }

}
而splash_-screen xml看起来是这样的:在您的绘图表中应该有任何名为“splash_-screen”的图像


现在,在清单文件中将您的初始屏幕设置为启动程序活动,使其成为启动活动。。 为了获得应用程序的标题栏,只需在清单中添加活动并添加主题,如下所示:

<activity android:name=".SplashScreen" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN">
                <category android:name="android.intent.category.LAUNCHER">
            </category></action></intent-filter>
        </activity>

访问以下关于Java(Swing)启动屏幕的优秀教程


在main方法中,您需要创建一个无边界的JFrame,它显示您的启动屏幕,然后睡眠几秒钟,剩下的工作使用前面讨论过的
SplashScreen
类。谁说这是针对Android的?
<activity android:name=".SplashScreen" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN">
                <category android:name="android.intent.category.LAUNCHER">
            </category></action></intent-filter>
        </activity>