当使用startActivity跳转到指定屏幕时,如果已经在当前任务中显示该屏幕,那么不应该添加FLAG_ACTIVITY_NEW_TASK标志,否则可能会导致多个任务同时打开同一个屏幕,从而影响用户体验。
示例代码:
// 错误方式: Intent intent = new Intent(this, RequiredActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 错误的添加FLAG_ACTIVITY_NEW_TASK标志 startActivity(intent);
// 正确方式: Intent intent = new Intent(this, RequiredActivity.class); startActivity(intent); // 不需要添加FLAG_ACTIVITY_NEW_TASK标志