2017-10-16 2 views
0

Je tente de créer une application Webview affichant un écran de démarrage une fois après le premier repas. Initialement, une fois que j'ouvre l'application l'écran de démarrage apparaîtra puis après 5 secondes, il chargera l'activité principale VaultActivity, mais après avoir ajouté la ligne de code pour vérifier si l'écran de démarrage 'SplashScreen' a été lancé auparavant, l'application a arrêté VaultActivity en utilisant le SPLASH_TIME_OUT je définis et aussi l'écran de démarrage apparaît toujours quand je déjeune l'application.L'écran Webview Splash ne s'affiche pas une fois comme prévu

Dans un premier temps

public class SplashScreen extends Activity { 

    private static int SPLASH_TIME_OUT = 5000; // Splash screen timer 

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

      new Handler().postDelayed(new Runnable() { 
       @Override 
       public void run() { 
        // Start main activity 
        Intent intent = new Intent(SplashScreen.this, VaultActivity.class); 
        startActivity(intent); 
        finish(); 
       } 
      }, SPLASH_TIME_OUT); 

    } 
} 

Actuellement

public class SplashScreen extends Activity { 

    private static int SPLASH_TIME_OUT = 5000; // Splash screen timer 

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

     SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE); 
     if(pref.getBoolean("activity_executed", false)){ 
      new Handler().postDelayed(new Runnable() { 
       @Override 
       public void run() { 
        // Start main activity 
        Intent intent = new Intent(SplashScreen.this, VaultActivity.class); 
        startActivity(intent); 
        finish(); 
       } 
      }, SPLASH_TIME_OUT); 
     } else { 
      SharedPreferences.Editor ed = pref.edit(); 
      ed.putBoolean("activity_executed", true); 
      ed.commit(); 
     } 
    } 
} 

Mon Manifest

<activity 
     android:name=".SplashScreen" 
     android:launchMode="singleTask" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <activity android:name=".VaultActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:scheme="http" 
       android:host="example.com" 
       android:pathPrefix="/androidmobile" /> 
     </intent-filter> 
    </activity> 

Répondre

0

:) il suffit d'ajouter startActivity dans la section else.

public class SplashScreen extends Activity { 



      private static int SPLASH_TIME_OUT = 5000; // Splash screen timer 

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

       SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE); 
final SharedPreferences.Editor ed = pref.edit() 
       if(pref.getBoolean("activity_executed", false)){ 
        //ed.putBoolean("activity_executed", true); 
        //ed.commit(); 

    Intent intent = new Intent(SplashScreen.this, VaultActivity.class); 
          startActivity(intent); 
          finish(); 
       } else { 
        new Handler().postDelayed(new Runnable() { 
         @Override 
         public void run() { 
          // Start main activity 
          Intent intent = new Intent(SplashScreen.this, VaultActivity.class); 
          startActivity(intent); 

        ed.putBoolean("activity_executed", true); 
        ed.commit(); 

          finish(); 
         } 
        }, SPLASH_TIME_OUT); 

       } 
      } 
     } 
+0

pas encore, je viens de tester et il ne pas le déjeuner à l'écran d'accueil sur le premier déjeuner puis sur le prochain déjeuner, il fait – Peter

0

Vous devez appeler l'étoile tActivity dans votre autre.