Android Splash Screen

匿名 (未验证) 提交于 2019-12-03 01:06:02

问题:

this is what i have in my package explorer so lets start from the top and work our way around to the problem where i think it is located..

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; }  }

now 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

splash.xml

AndroidManafest.xml

now i think my problem is in AndroidManafest.xml i dont think i have the splach screen set up right in the AndroidManafest.xml when i launch my application from my phone it jumps to activity_main.xml and not splash.xml im new to android applications so i cant seem to find my problem but i need my splash screen to show for 5 seconds if anyone has TeamViwer and would like to help me ill post my session info if it will be faster.

回答1:

Change your tag to the following. You didn't have SplashActivity declared, and had your MainActivity setup as the launcher Activity.



回答2:

The Best way implement a splash screen, to be displayed every time your application is launched will be to create a new activity.

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(); } }


回答3:

You can easily access splash screen like this. such as

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);      } }

it will be works 100%.



回答4:

welcome this Splash screen do animation for Image and finish :)

    //splash screen 


回答5:

@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



转载请标明出处:Android Splash Screen
文章来源: Android Splash Screen
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!