我有以下代码。
public class SplashScreen extends Activity {
private int _splashTime = 5000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
new Handler().postDelayed(new Thread(){
@Override
public void run(){
Intent mainMenu = new Intent(SplashScreen.this, MainMenu.class);
SplashScreen.this.startActivity(mainMenu);
SplashScreen.this.finish();
overridePendingTransition(R.drawable.fadein, R.drawable.fadeout);
}
}, _splashTime);
}
}
我在分析这段代码时遇到问题。据了解处理程序正在主线程中运行。但它有在其他线程中运行的线程。
MainMenu.class将在主线程或第二线程中运行?如果主线程停止 5 秒 ANR 将被提高。为什么当我延迟停止它时(_splashTime)
ANR 不显示(即使我将它增加到超过 5 秒)