In your career reading Android source code, have you seen where the singleton pattern is used in the Android framework layer or third-party frameworks? What is the way to implement the singleton pattern?

in the Android source code you read, where have you seen the singleton pattern used in the Android framework layer or third-party frameworks? What is the way to implement the singleton pattern?


EventBus,

    /** Convenience singleton for apps using a process-wide EventBus instance. */
    public static EventBus getDefault() {
        EventBus instance = defaultInstance;
        if (instance == null) {
            synchronized (EventBus.class) {
                instance = EventBus.defaultInstance;
                if (instance == null) {
                    instance = EventBus.defaultInstance = new EventBus();
                }
            }
        }
        return instance;
    }

android source code contains a lot of singleton patterns, such as the following implementation: static method with Synchronize lock

 public static WindowManagerGlobal getInstance() {
        synchronized (WindowManagerGlobal.class) {
            if (sDefaultWindowManager == null) {
                sDefaultWindowManager = new WindowManagerGlobal();
            }
            return sDefaultWindowManager;
        }
    }

too many, such as the commonly used LinkMovementMethod

    public static MovementMethod getInstance() {
        if (sInstance == null)
            sInstance = new LinkMovementMethod();

        return sInstance;
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e958f7-47341.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e958f7-47341.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?