ANN: Couchbase Lite Android - API change to Manager constructor

87 views
Skip to first unread message

Traun Leyden

unread,
Mar 14, 2014, 3:54:39 PM3/14/14
to mobile-c...@googlegroups.com
The Manager constructor has been changed from:

public Manager(File dir, ManagerOptions options) throws IOException 

to:

public Manager(Context context, ManagerOptions options) throws IOException

in order to be able to implement Network Aware sync.

Note that the Context object passed in is a com.couchbase.lite.Context, which wraps an android.content.Context, and certain calls are simply proxied down to the wrapped android.content.Context.

The normal way to create a Manager instance now is as follows:

        AndroidContext androidContext = new AndroidContext(getApplicationContext());
        
        manager = new Manager(androidContext, Manager.DEFAULT_OPTIONS);

However, you can also customize the AndroidContext, for example you can call setNetworkReachabilityManager() to have it use your own implementation if you want to fine-tune how it reacts to Android network reachability events, or possibly disable it completely.  

An example of doing that:


        AndroidContext androidContext = new AndroidContext(getApplicationContext());
        androidContext.setNetworkReachabilityManager(new NetworkReachabilityManager() {
            @Override
            public void startListening() {
                // do nothing
            }

            @Override
            public void stopListening() {
                // do nothing
            }
        });
        manager = new Manager(androidContext, Manager.DEFAULT_OPTIONS);


This has recently been pushed to the master branch, let me know if you run into problems.

Reply all
Reply to author
Forward
0 new messages