How do you stop an Observer manually?

I want to unregister an Observer for various reasons. How do I go about this without having to tear down a GroundSdk session?

groundSdk = GroundSdk.newSession(ctx, null);
groundSdk.resume();

...

groundSdk.getDroneList(it -> true, droneListObserver);

dronelistObserver onChange() fires and action is taken. I no longer have need for the Observer in the current Activity and I do not want to rely on the Activity lifecycle to manage suspending / resuming it.

Hi synman,

When you request something observable from groundsdk APIs and provide a Ref.Observer<T> of some kind, as in your code sample, you get a Ref<T> in return.

This is basically your hook onto both the observed data (you can call get() on it to fetch current data) but more importantly also onto the observer itself: you can use Ref.close() method to unsubscribe from observer change notifications. Once you call close(), your observer won’t be called anymore.

This is what you should use in your situation.

Regards.

So basically,

final Ref<List> droneListRef = groundSdk.getDroneList(it -> true, droneListObserver);

.... do stuff ....

droneListRef.close();

Kicking myself, as I’ve worked with the Ref object previously and missed the close() method.

Thanks!