最初に数秒間アプリにsplashScreenを表示してから、Javaでタイマーを使用してすべてのスレッドデータをロードしたいのですが、どうすればよいですか。
2 に答える
            0        
        
		
プロジェクトにスプラッシュ スクリーン アクティビティを追加します... 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」という名前のドローアブルに画像が必要な場所
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/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>
于 2013-07-07T14:00:09.780   に答える