Support Topics Documentation Slack YouTube Blog

removeUpdateListener() and removeBulkUpdateListeners() do not work anything

Backendless Version (5.x, Developer)

Client SDK (Android)

Application ID: 43B8A63C-CC25-BE19-FFD0-A47A21B9BC00

I called removeUpdateListener() and removeBulkUpdateListeners() from sdk but nether handleResponse called nor handleFault called. I wrote code with two approaches but no one do anything i expected. please help me if you can.

  1. add update listener and bulk update listener on Device Table, every things ok:

       final EventHandler<Map> lockObjectUpdate = Backendless.Data.of("Device").rt();
       lockObjectUpdate.addUpdateListener(String.format("objectId='%s'", mDevice.getObjectId()), new     AsyncCallback<Map>() {
         @Override
         public void handleResponse(Map updatedLock) {
             updatedLock.put("bleDeviceName", mDevice.getBleDeviceName());
             updatedLock.put("memberAdminStatus", mDevice.getUserAdminStatus());
             listener.onResponse(new Device(updatedLock));
         }
    
         @Override
         public void handleFault(BackendlessFault fault) {
             listener.onSingleNetworkListenerFailure(new FailureModel(fault.getMessage()));
         }
     });
    
     final EventHandler<Map> lockObjectBulkUpdate = Backendless.Data.of("Device").rt();
     lockObjectBulkUpdate.addBulkUpdateListener(String.format("sn='%s'", mDevice.getSerialNumber()), new AsyncCallback<BulkEvent>() {
         @Override
         public void handleResponse(BulkEvent response) {
             if (response.getCount() >= 1) {
                 listener.onResponse(new TempDeviceModel(mDevice.getObjectId()));
             }
         }
    
         @Override
         public void handleFault(BackendlessFault fault) {
             listener.onSingleNetworkListenerFailure(new FailureModel(fault.getMessage()));
         }
     });
    

Then after some time, i removed listeners but listener after call these lines still are exist;

First Approach:
Backendless.Data.of(“Device”).rt().removeUpdateListeners();
Backendless.Data.of(“Device”).rt().removeBulkUpdateListeners();

Second Approach:
Backendless.Data.of(“Device”).rt().removeBulkUpdateListener(
String.format(“sn=’%s’”, mDevice.getSerialNumber()), new AsyncCallback() {
@Override
public void handleResponse(BulkEvent response) {
Timber.d(“removeListenerForDevice1 done!”);
}

                @Override
                public void handleFault(BackendlessFault fault) {
                    Timber.d("removeListenerForDevice1 done!");
                }
            });
    Backendless.Data.of("Device").rt().removeUpdateListener(
            String.format("objectId='%s'", mDevice.getObjectId()), new AsyncCallback<Map>() {
                @Override
                public void handleResponse(Map response) {
                    Timber.d("removeListenerForDevice2 done!");
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Timber.d("removeListenerForDevice2 done!");
                }
            });

Just to make sure I understood the problem… Are you saying you still receive the update and 'bulkUpdate` events even after the listeners are removed?

Hi, Yes exactly. This is my AppId: 43B8A63C-CC25-BE19-FFD0-A47A21B9BC00

Thanks. Could you please let me know what version of the Backendless SDK for Android you use?

Hi, sure.
‘com.backendless:backendless:5.2.2’

Try the following approach:

lockObjectUpdate.removeUpdateListeners();
lockObjectBulkUpdate.removeBulkUpdateListeners();

Meanwhile we’ll look into why the approach you’ve mentioned not working

BTW, the approach I’ve mentioned is the only documented way for removing listeners https://backendless.com/docs/android/rt_removing_listeners_update.html
Anyways I’ll get back to you with additional info

Anton

You mean, i save lockObjectUpdate instance after set listener and every when i want remove listener, use exactly same object. Am i right?

You are creating RT handler as followed:
final EventHandler<Map> lockObjectUpdate = Backendless.Data.of("Device").rt();

than adding listeners to it:
lockObjectUpdate.addUpdateListener(String.format......)

You’ll need to call removeListeners method against every EventHandler instance you created

Anton

From the documentation:

Removing Listeners

Listener objects can be removed when the application is no longer interested in receiving real-time updates. A listener (or all of them) should be removed from the same event handler object which they were added to.

I’d suggest to read the docs first, it will make things a bit more clear :wink:

That’s it, you’re right. thank you so much. I’ll try it.