java - SplashScreen finish() 应用程序最小化后

标签 java android multithreading runnable

我正在使用 finish() 来结束 SplashScreen Activity 中的线程,当我这样做时,应用程序会在转到 Activity2 之前最小化。如何结束 SplashScreen Activity 并转到 Activity2 而不调用 finish() 以便应用程序不会最小化?

public class SplashScreen extends Activity {

    /**
     * The thread to process splash screen events
     */
    private Thread mSplashThread;    

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Splash screen view
        setContentView(R.layout.splash);

        final SplashScreen sPlashScreen = this;   

        // The thread to wait for splash screen events
        mSplashThread =  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        // Wait given period of time or exit on touch
                        wait(5000);
                    }
                }
                catch(InterruptedException ex){                    
                }

                finish();

                // Run next activity
                Intent intent = new Intent();
                intent.setClass(sPlashScreen, MainActivity.class);
                startActivity(intent);
                //stop();                    
            }
        };

        mSplashThread.start();        
    }

    /**
     * Processes splash screen touch events
     */
    @Override
    public boolean onTouchEvent(MotionEvent evt)
    {
        if(evt.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(mSplashThread){
                mSplashThread.notifyAll();
            }
        }
        return true;
    }    
} 

最佳答案

startActivity后调用finish

    mSplashThread =  new Thread(){
        @Override
        public void run(){
            try {
                synchronized(this){
                    // Wait given period of time or exit on touch
                    wait(5000);
                }
            }
            catch(InterruptedException ex){                    
            }


            // Run next activity
            Intent intent = new Intent();
            intent.setClass(sPlashScreen, MainActivity.class);
            startActivity(intent);



            //call finish after startActivity
            finish();
            //stop();                    
        }
    };

    mSplashThread.start();        

关于java - SplashScreen finish() 应用程序最小化后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18664764/

相关文章:

Javafx 实时线程更新

java图像处理sobel边缘检测

java - 如何从 json 数组中检索数据并显示在 textview 中?

安卓警告 "This TableRow view is useless (no children, no background, no id)"

安卓自定义字体

java - 一旦我将 Runnable 传递给不同线程中的 Swing 的 invokeAndWait ,就无法停止它

java - JaCoCo报告格式

java - 是否要延迟加载以努力提高性能

android - 更改油漆颜色时,现有笔划也会更改

c# - 启动画面显示方法最佳实践C#