gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:36:06 29 4
gpt4 key购买 nike

我正在使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com