2017-07-31 7 views
0

私は動作しているスプラッシュスクリーンの動作をしています。しかし、ユーザーが戻るボタンを押すと、アプリケーションを再開した後、私はスプラッシュスクリーンを表示したくありません。どうやってやるの ?スプラッシュスクリーンを表示する新鮮なオープン時のみ

SplashScreen.java

public class SplashScreen extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_splash); 

     Thread t = new Thread() { 
      public void run() { 
       try { 
        int time = 0; 
        while (time < 4000) { 
         sleep(100); 
         time += 100; 
        } 
       } 
       catch (InterruptedException e) { 
        // do nothing 
       } 
       finally { 

        Intent i = new Intent(SplashScreen.this, MainActivity.class); 
        startActivity(i); 
        finish(); 
       } 
      } 
     }; 
     t.start(); 

    } 
} 

のAndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.fardrop.radarso"> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher" 
     android:supportsRtl="true" 
     android:theme="@style/app_theme"> 

     <activity 
      android:name="com.fardrop.radarso.SplashScreen" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:theme="@android:style/Theme.Black.NoTitleBar" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    <activity android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleInstance" 
      android:alwaysRetainTaskState="true" 
      android:icon="@mipmap/ic_launcher" 
      android:screenOrientation="portrait" 
      android:theme="@style/AppTheme"> 
     </activity> 

    </application> 

</manifest> 
+2

がhttps://stackoverflow.com/questions/20641580/show-splash-screen-one-time-only –

+1

が共有県、チェックであなたのスプラッシュ画面の状態を保存参照してくださいさらに明確化のための答え下記を参照することができます それはspalsh画面のonCreateにあり、ユーザーがすでに訪問した場合は単にホーム画面に移動します –

答えて

1

この

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    requestWindowFeature(Window.FEATURE_NO_TITLE); 

    setContentView(R.layout.activity_splash); 
    new Handler().postDelayed(new Runnable() {  
    @Override 
    public void run() { 
     startActivity(new Intent(SplashActivity.this, MainActivity.class)); 
     finish(); 
     // close this activity 

     /* or this 
     Intent intent = new Intent(LoginActivity.this, HomeScreenActivity.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     startActivity(intent);*/ 

    } 
}, 3000);// time for spalsh screen 
+0

両方の方法を試してみましたが、まだスプラッシュが表示されています: – user3304007

1

は単にSplashActivityのコードの下に使用してみてください。

new Handler().postDelayed(new Runnable() { 

        @Override 
        public void run() { 
         try { 
          Intent i = new Intent(SplashScreen.this, HomeScreenActivity.class); 
          startActivity(i); 
          finish(); 
         } 
         catch (final Exception e) 
         { 
          runOnUiThread(new Runnable(){ 
           @Override 
           public void run() { 
            Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); 
           } 
          }); 
         } 

        } 
       }, 2*1000); 
0

あなたの店というSharedPreferencesで、あなたはスプラッシュ画面を表示するためsharedPreferencesから値を取得し、再び見せながらお見えフラグ。あなたは show splash screen one time only

関連する問題