首页 > 解决方案 > 如何避免在后台运行时启动应用程序时显示启动画面?

问题描述

仅在重新启动时显示启动画面,而不是在后台运行时启动应用程序时显示。这是飞溅活动的代码。

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);

}

}

标签: javaandroidandroid-fragmentsandroid-activityandroid-lifecycle

解决方案


为显示初始屏幕创建新活动。然后在你的 AndroidManifest.xml 中移动

<intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter>

从 MainActivity 到您的启动活动标签


推荐阅读