问题:按 home 键退出到桌面,在点击应用图标会再次打开 launcher Acitvity。
解决:启动的 Activity 添加如下优化。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 不是在栈的根部
if (!this.isTaskRoot()) {
Intent intent = getIntent();
if (intent != null) {
String action = intent.getAction();
// // 当前类是从桌面启动
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
finish();
return;
}
}
}
setContentView(R.layout.activity_main);
initView();
}