Android 开发 启动activity并且将前面activity全部清空

方法一

Intent intent = new Intent(A.this,B.class);
 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);  
 startActivity(intent); 

方法二

 Intent intent = new Intent(context,PLoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(intent);   

方法三

/**
 *@content:活动结束管理类
 *@time:2019-1-29
 *@build:
 */

public class ActivityFinishUtil {
    private static List<Activity> activityList = new ArrayList<>();

    public static void addActivity(Activity activity){
        activityList.add(activity);
    }

    public static void removeActivity(Activity activity){
        activityList.remove(activity);
    }

    public static void finishOtherAllActivity(Activity activity){
        for (Activity item : activityList){
            if (item == activity){
                continue;
            }
            item.finish();
        }
    }

    public static void finishAllActivity(){
        for (Activity item : activityList){
            item.finish();
        }
    }

}

 

posted @ 2020-05-29 14:33  青竹玉简  阅读(544)  评论(0编辑  收藏  举报