【发布时间】:2020-08-26 13:49:40
【问题描述】:
仅在重新启动时显示启动画面,而不是在后台运行时启动应用程序时显示。这是splash活动的代码。
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_intro);
Handler handler = new Handler();
handler.postDelayed(() -> {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
},2000);
}
}
【问题讨论】:
-
我之前已经看到过这个问题,这不是我想要的。
-
我建议反对这个代码,你只是无缘无故地给你的应用程序的启动时间增加了两秒的“滞后”,这可能会激怒你用户。我强烈推荐this 之类的东西。
标签: java android android-fragments android-activity android-lifecycle