2013-03-16 1 views
14

My Package ExplorerAndroid Splash Screen

ce que j'ai dans mon explorateur de package permet donc commencer par le haut et de travailler notre chemin au problème où je pense qu'il se trouve ..

MainActivity.java -

package com.drg.idoser; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

public class MainActivity extends Activity { 

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

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

} 

maintenant SplashActivity.java

package com.drg.idoser; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Window; 
import android.view.WindowManager; 

public class SplashActivity extends Activity { 

private static String TAG = SplashActivity.class.getName(); 
private static long SLEEP_TIME = 5; // Sleep for some time 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar 

    setContentView(R.layout.splash); 

    // Start timer and launch main activity 
    IntentLauncher launcher = new IntentLauncher(); 
    launcher.start(); 
} 

private class IntentLauncher extends Thread { 
    @Override 
    /** 
    * Sleep for some time and than start new activity. 
    */ 
    public void run() { 
    try { 
     // Sleeping 
     Thread.sleep(SLEEP_TIME*1000); 
    } catch (Exception e) { 
     Log.e(TAG, e.getMessage()); 
    } 

    // Start main activity 
    Intent intent = new Intent(SplashActivity.this, MainActivity.class); 
    SplashActivity.this.startActivity(intent); 
    SplashActivity.this.finish(); 
    } 
} 
} 

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

</RelativeLayout> 

splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:background="@drawable/splash_bg" 
android:layout_height="match_parent" 
android:orientation="vertical" > 


</LinearLayout> 

AndroidManafest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.drg.idoser" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.drg.idoser.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 

maintenant je pense que mon problème est dans AndroidManafest.xml je ne pense pas que j'ai le splach écran mis en place à droite dans le AndroidManafest.xml lorsque je lance mon application à partir de mon téléphone, il saute à activity_main.xml et non splash.xml im nouveau aux applications android donc je ne peux pas sembler trouver mon problème mais j'ai besoin de mon écran de démarrage pour montrer pendant 5 secondes si quelqu'un a TeamViwer et voudrait m'aider à poster ma session info si ce sera plus rapide.

+1

pour ceux qui pourraient copier au-dessus du code de l'écran de démarrage, fortement recommandé ** pas ** à utiliser du fil. Au lieu de cela, utilisez Handler. consultez le lien http://stackoverflow.com/a/12195205/361100 – Youngjae

+0

voir ce https://github.com/meetmehdi/GoodSplash –

Répondre

25

Modifiez votre balise <application> en procédant comme suit. Vous n'avez pas déclaré SplashActivity et votre configuration MainActivity était l'activité de lancement.

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.drg.idoser.SplashActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.drg.idoser.MainActivity" 
     android:label="@string/app_name" /> 
</application> 
+0

merci cela a fonctionné :) –

+0

je l'ai essayé dit s'il vous plaît attendez 25 min je ne sais pas pourquoi –

+0

A travaillé parfait pour moi. Merci – Zapnologica

1

Vous pouvez facilement accéder à l'écran de démarrage comme ceci. tel que

public class MainActivity extends Activity { 
    private ImageView splashImageView; 
    private boolean splashloading = false; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     splashImageView = new ImageView(this); 
     splashImageView.setScaleType(ScaleType.FIT_XY); 
     splashImageView.setImageResource(R.drawable.ic_launcher); 
     setContentView(splashImageView); 
     splashloading = true; 
     Handler h = new Handler(); 
     h.postDelayed(new Runnable() { 
      public void run() { 
       splashloading = false; 
       // set your layout file in below 
       setContentView(R.layout.activity_main); 
      } 
     }, 3000); 

    } 
} 

cela fonctionnera à 100%.

-1
@Override 

    protected void onCreate(Bundle savedInstanceState) { 

      super.onCreate(savedInstanceState); 

      setContentView(R.layout.activity_main); 

      Thread th = new Thread(new Runnable() {   /*create a new thread */ 

           @Override 

           public void run() { /* 

                    * The purpose of this thread is to 

                    * navigate from one class to another 

                    * after some time 

                    */ 

            try { 

              Thread.sleep(5000); 

            } catch (InterruptedException e) { 

              /* 

              * We are creating this new thread because we don’t 

              * want our main thread to stop working for that 

              * time as our android stop working and some time 

              * application will crashes 

              */ 

              e.printStackTrace(); 

            } 

            finally { 

              Intent i = new Intent(MainActivity.this, 

                  Splash_Class.class); 

              startActivity(i); 

              finish(); 

            } 

           } 

         }); 

      th.start(); // start the thread 

    } 

http://www.codehubb.com/android_splash_screen

+0

Veuillez corriger votre tabulation! –

+3

Une explication serait bien. Juste un vidage de code n'est pas utile. –

+0

Bienvenue dans Stack Overflow! S'il vous plaît citer la partie la plus pertinente du lien, au cas où le site cible est inaccessible ou se déconnecte définitivement.Voir [Comment écrire une bonne réponse] (http://stackoverflow.com/help/how-to-answer). – Gattsu

2

La meilleure façon mettre en œuvre un écran d'accueil, à afficher chaque fois que votre application est lancée sera de créer une nouvelle activité.

public class SplashScreen extends Activity { 

private Handler mHandler; 

private Runnable myRunnable; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // Just create simple XML layout with i.e a single ImageView or a custom layout 
    setContentView(R.layout.splash_screen_layout); 
    mHandler = new Handler(); 
    myRunnable = new Runnable() { 
     @Override 
     public void run() { 
      Intent intent = new Intent(SplashScreen.this, MainActivity.class); 
      startActivity(intent); 
      finish(); 
     } 
    }; 

} 

@Override 
public void onBackPressed() { 
// Remove callback on back press 
    if (mHandler != null && myRunnable != null) { 
     mHandler.removeCallbacks(myRunnable); 
    } 
    super.onBackPressed(); 
} 

@Override 
protected void onPause() { 
// Remove callback on pause 
    if (mHandler != null && myRunnable != null) { 
     mHandler.removeCallbacks(myRunnable); 
    } 
    super.onPause(); 
} 

@Override 
protected void onResume() { 
// Attach and start callback with delay on resume 
    if (mHandler != null && myRunnable != null) { 
     mHandler.postDelayed(myRunnable, ConstantValues.SPLASH_TIME_OUT); 
    } 
    super.onResume(); 
} 
} 
0

bienvenue cet écran Splash faire de l'animation pour l'image et finir :)

//splash screen < 

ImageView image = (ImageView) findViewById(R.id.s_logo); 

    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.jump_up); 
    image.startAnimation(animation); 


    Thread thread = new Thread() { 
     public void run() { 
      try { 
       sleep(5000); 
       Intent intent = new Intent(getApplicationContext(), MainActivity.class); 
       startActivity(intent); 
       finish(); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 
    }; 
    thread.start(); 

    //splach screen />