如何避免在后台运行时启动应用程序时显示初始屏幕?



仅在后台运行时启动应用程序时在全新启动时显示初始屏幕。 下面是启动活动的代码。

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

}

为显示初始屏幕创建新活动。然后在您的 Android 清单中.xml移动

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

从主活动到您的启动活动标签

通常,在后台运行的应用在被调用到前端时会恢复到其先前访问的活动/片段。如果在初始屏幕恢复时遇到初始屏幕,则说明您没有正确管理活动生命周期。

最新更新