为什么使用isTaskRoot
代码中如何使用呢?
package com.gsmc.qy.sport.ui.module.splash;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.gsmc.qy.sport.ui.base.BaseActivity;
import com.gsmc.qy.sport.ui.base.BaseFragment;
import static com.gsmc.qy.sport.data.constant.RouterPathConstant.FRAGMENT_FLAG;
import static com.gsmc.qy.sport.data.constant.RouterPathConstant.SPLASH;
@Route(path = SPLASH)
public class SplashActivity extends BaseActivity {
@Override
protected String getRouterPath() {
return SPLASH + FRAGMENT_FLAG;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
if (!isTaskRoot()) {
Intent mainIntent = getIntent();
String action = mainIntent.getAction();
if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
} catch (Exception e) {
}
}
}