• 如下集合类可以让我随时随地添加、退出程序


    今天我所要作的笔记是:

    当我们的程序需要一个添加、注销或者退出的功能,只需要一个专门的集合类对所有的活动进行管理。代码如下。

    
    import android.app.Activity;
    
    import java.util.ArrayList;
    
    import java.util.List;
    
    public class ActivityCollector {
    
    public static Listactivities =new ArrayList<>();
    
        //添加某一个活动
    
        public static void addActivity(Activity activity){
    
            activities.add(activity);
    
        }
    
        //移除某一个活动
    
        public static void removeActivity(Activity activity){
    
            activities.remove(activity);
    
        }
    
        //关闭所有活动
    
        public static void finishAll(){
    
    
    public class ActivityCollector {
        public static List<Activity> activities =  new ArrayList<>();
    
        //添加某一个活动
        public static void addActivity(Activity activity){
            activities.add(activity);
        }
    
        //移除某一个活动
        public static void removeActivity(Activity activity){
            activities.remove(activity);
        }
    
        //关闭所有活动
        public static void finishAll(){
            for (Activity activity : activities){
                if (!activity.isFinishing()){
                    activity.finish();
                }
            }
            activities.clear();
        }
    }
    
    The one who wants to wear the crown, bears the crown.
  • 相关阅读:
    CentOS-Docker安装RabbitMQ集群(rabbitmq:3.7.16-management)
    Xcode Shortcuts
    In App Purchase
    CoreData
    Sandbox 文件存放规则
    在 mac os 上搭建 git server
    Git
    Git and Xcode
    心算技巧
    AppleScript
  • 原文地址:https://www.cnblogs.com/catherineliu/p/13048313.html
Copyright © 2020-2023  润新知