简体   繁体   中英

singelton object in sync adapter class

I need help regarding the explanation of

why do we use a singleton object in sync adapter service class

private static SyncAdapter sSyncAdapter = null;
private static final Object sSyncAdapterLock = new Object();

    @Override
    public void onCreate() {
        synchronized (sSyncAdapterLock) {
            if (sSyncAdapter == null) {
                sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
            }
        }
    }

Because the Framework is build in the way to work with only one SyncAdapter:

The sync adapter framework is designed to work with sync adapter components that are singleton instances.

You can have multiple component triggering the SyncAdapter to send some data. But you only want to create ONE SyncAdapter to manage all the calls. Therefore you create the SynAdapter with the singleton-pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM