// 避免从桌面启动程序后,会重新实例化入口类的activity
if (!this.isTaskRoot()) { // 当前类不是该Task的根部,那么之前启动
Intent intent = getIntent();
if (intent != null) {
String action = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) { // 当前类是从桌面启动的
finish(); // finish掉该类,直接打开该Task中现存的Activity
return;
}
}
}
避免从桌面启动程序后,会重新实例化入口类的activity
最新推荐文章于 2021-12-02 11:22:03 发布