问题描述
http://p-xr .com/android-tutorial-to-make-a-basic-splash-screen/
问题是,如果用户在飞溅屏幕持续时间期间击中主页按钮或返回按钮以退出应用程序,那么如果用户执行了在飞溅屏幕之后将重新打开到第二屏幕没有退出.
我的代码几乎是教程的代码.任何帮助?
感谢
推荐答案
我已修改代码以更好地利用生命周期方法.享受改变它. :)
public class SplashScreen extends Activity { protected int _splashTime = 5000; private Thread splashTread; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); final SplashScreen sPlashScreen = this; // thread for displaying the SplashScreen splashTread = new Thread() { @Override public void run() { try { synchronized(this){ wait(_splashTime); } } catch(InterruptedException e) {} finally { if(!isFinishing()) // This pretty useful boolean val tells if //user has pressed the back button. very useful. {Intent i = new Intent(SplashScreen.this, Main.class); startActivity(i); finish(); } stop(); } } }; splashTread.start(); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Toast.makeText(this,"exec---",Toast.LENGTH_LONG).show(); synchronized(splashTread){ splashTread.notifyAll(); } } return true; } @Override protected void onPause() { super.onPause(); if(splashTread.getState()==Thread.State.TIMED_WAITING){ //Thread is still waiting and Activity is paused. Means user has pressed Home. Bail out finish(); } } }
我的观点是使用飞溅屏幕不频繁,但可能需要.如果你在屏幕后面做了繁重的工作(如游戏).
问题描述
Ok, so i created a very simple splash screen using this tutorial:
http://p-xr.com/android-tutorial-how-to-make-a-basic-splash-screen/
The problem is that if the user hits the home button or the back button to exit the app during the splash screens duration then the app will re-open to the second screen after the splash screen would have been done if the user did no exit.
My code is pretty much that of the tutorial. any help?
Thanks
推荐答案
I have modified the code to make use of the lifecycle methods better. enjoyed changing it. :)
public class SplashScreen extends Activity { protected int _splashTime = 5000; private Thread splashTread; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); final SplashScreen sPlashScreen = this; // thread for displaying the SplashScreen splashTread = new Thread() { @Override public void run() { try { synchronized(this){ wait(_splashTime); } } catch(InterruptedException e) {} finally { if(!isFinishing()) // This pretty useful boolean val tells if //user has pressed the back button. very useful. {Intent i = new Intent(SplashScreen.this, Main.class); startActivity(i); finish(); } stop(); } } }; splashTread.start(); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Toast.makeText(this,"exec---",Toast.LENGTH_LONG).show(); synchronized(splashTread){ splashTread.notifyAll(); } } return true; } @Override protected void onPause() { super.onPause(); if(splashTread.getState()==Thread.State.TIMED_WAITING){ //Thread is still waiting and Activity is paused. Means user has pressed Home. Bail out finish(); } } }
My point of view is that the use of Splash Screen is not frequent but maybe needed. If you are doing heavy work behind the screen( such as games).