Support Topics Documentation Slack YouTube Blog

addUpdateListener does not get trigger!

Hi, I am using a realtime database!
My problem is I have implemented the code for the real-time update listener and this listener is not triggered when I update the object in my table dynamically but it gets trigger when I manually change the value using the console.

By dynamically I mean when I update the field in a table using API the addUpdateListener does not trigger but when u manually go and log into my backless account and then in my table when I change the value the addUpdateListener gets triggered

Hello,

Please provide more details, such as:

  1. Is your listener conditional or unconditional?
  2. Can you show the code which performs object update?

Mark

I double check as using console the object gets updated but it is not triggering the listener for update through code or calling update api
here is my code to update the object

            Map update = new HashMap();
            update.put( Constants.RIDE_SELECTED, "--HEHE--" );

            Backendless.Data.of( "PassengerChauffeurConnection" ).update(null, update, new AsyncCallback<Integer>() {
                @Override
                public void handleResponse(Integer response) {
                    Toast.makeText(IncomingJobDetails.this, "Updated ", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Toast.makeText(IncomingJobDetails.this, "Failed: "+ fault.getMessage(),  Toast.LENGTH_SHORT).show();

                }
            });

My object is updating without an issue !!
and here I am listening the below listener only trigger when I manually change the value from console

  EventHandler<PassengerChauffeurConnection> rtHandler = Backendless.Data.of(PassengerChauffeurConnection.class).rt();
        rtHandler.addUpdateListener(new AsyncCallback<PassengerChauffeurConnection>() {
            @Override
            public void handleResponse(PassengerChauffeurConnection jobCreated) {


                ShowIncomingJobNotification.sendOnChannelIncomingJobNotification(getApplicationContext() ,
                        "Payback" ,
                        R.drawable.email_black , R.color.colorBackground);

            }

            @Override
            public void handleFault(BackendlessFault fault) {

                Toast.makeText(SendingRideRequestService.this, "Failed to get update: " + fault.getMessage() , Toast.LENGTH_SHORT).show();
            }
        });

I am using unconditional listener

Your “update” code uses the “bulk update” API, which is updating multiple objects:
https://backendless.com/docs/android/data_multiple_objects_bulk_update.html

However, the listener you’re adding is a single listener, instead of this one:
https://backendless.com/docs/android/rt_bulk_update_listener.html

Additionally, the update code is passing null where a where clause is expected:
addUpdateListener does not get trigger! - Android - Backendless Support 2020-05-30 09-32-30

Regards,
Mark

I did both updating and listing for the single object
instead of null, I pass the where-clause and only single field gets updated as I want
but the issue still exists as the addUpdateListener does not trigger (using code) but gets trigger using console manual updating.

> Map update = new HashMap();
        update.put( Constants.RIDE_SELECTED, "--HEHE--" );

        Backendless.Data.of( "PassengerChauffeurConnection" ).update(Constants.TOKEN +" = " + sharedPreferences.getInt(Constants.TOKEN , 0), update, new AsyncCallback<Integer>() {
            @Override
            public void handleResponse(Integer response) {
                Toast.makeText(IncomingJobDetails.this, "Updated baby", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                Toast.makeText(IncomingJobDetails.this, "Failed: "+ fault.getMessage(),  Toast.LENGTH_SHORT).show();

            }
        });

addUpdateListener code working fine only when I manual update the field but when I update the field using code (API) the field gets updated but listener does not get’s triggered

When you use the bulk update API, the addUpdateListener will not be triggered. It gets triggered when you use the API to update a single object with this:
https://backendless.com/docs/android/data_single_object_update.html

A listener for the bulk update API must be added as documented here:
https://backendless.com/docs/android/rt_bulk_update_listener.html

Regards,
Mark

.save

creating new object in database and not updating the existing object that’s why i use

.update

method

The save method updates a single object.
The update method updates multiple objects.

The save method will trigger a listener added with addUpdateListener.
The update method will trigger a listener added with addBulkUpdateListener

Thank you these lines solved my problem.
The save method updates a single object.
The update method updates multiple objects.

The save method will trigger a listener added with addUpdateListener .
The update method will trigger a listener added with addBulkUpdateListener

But one thing you are wrong about
.save method creates a new object not updating the existing object (updating single property)

If the object you pass into the save method does not have objectId, then a new object is created. If objectId is there with a value, then the object is updated.

1 Like

i see as i don’t have any objectId that’s why a new object get’s created.
Thanks for helping me out !!