addMessageListener in Real time messaging shows empty message after 5 calls

Hi,

I am developing an Android app, in which I am testing the real time messaging. In my app, I have a fragment in which I test the real time messages, and from my main activity I call this fragment. Everything works great.
Now, when I exit from the fragment and go back to the activity then call the fragment then exit,then call it again, I noticed if I do this (exit then call the fragment) few times (5 times), the messages will not show up.
Is there is a limit to the number of times I can receive messages? or there is something else wrong

Please advise

Thanks,
Mohammed

Hello,

Please provide the minimal verifiable code sample so we could check this issue.

Regards, Olga

Hi Olga,

Please see the attached zip file which I verified as you requested. Please know that I have removed my application ID and API key from the Default class for the sake of privacy, but like I said I verified the issue before I remove keys and compress the project
please let me know, if you need more information

Thanks,
Mohammed

msg_real_time_test.zip (140.2kB)

Thanks a lot,

also, we need steps to reproduce it, for example:

  1. Run main activity
  2. Press button “A button”
  3. Press other button

Result:
Something goes wrong: bad log message or there is no message somewhere

Expected result:
Some message in the log or tile or anything

Hi Sergey,

So, from the main screen the user puts user name and hits Go button and will go to message screen and when the user hits back button goes back to the main screen and if the user do the same thing by clicking the Go button will be directed to the message screen. Now if I do this scenario 5 times, I do not see any messages get delivered / shown in the messages in the message screen.
See the attached pdf with screen shots

Please let me know, if you need more clarification

Thanks,
Mohammed

reat_time_messages.pdf (188.31kB)

Hi Mohammed,

Thank you for the sample and problem description. Unfortunately, I couldn’t reproduce the missing messages even after 5 times going back and forth.
I suggest you to add some logging to the error handlers in your AsyncCallbacks so that you could see the error you receive when the messages do not arrive.

Hi Sergey,

I have trace it through debug and got the following error: BackendlessFault{ code: ‘null’, message: ‘{message=Reached Limit: you can not have more then 5 subscriptions per one connection, code=0, details={limit=5}}’, detail: ‘null’, extendedData: ‘{}’

how can remove or increase the limit?

Thanks,
Mohammed

Either you remove subscriptions when you don’t need them, or upgrade the billing plan to increase the limit.

Hi Sergey,

How do I remove subscriptions ?

Thanks,
Mohammed

See the documentation:

https://backendless.com/docs/android/doc.html#rt_removing_listeners
https://backendless.com/docs/android/doc.html#rt_removing_listeners_update

Hi Mark,

I tried channel.removeAllMessageListeners() in the onDestroy() callback and still facing the same issue

Thanks,
Mohammed

What is the logic behind adding it to the onDestroy() callback? Your app accumulates listeners when you go back and forth between the chat window. Look for adding listeners there

Hi Mark,

Sorry I was away and didn’t answer you earlier. I have copied the code generated by Code generation from your platform. the code uses channel.leave

this initially caused the issue to happen after 5 tries (please see initial comments of this thread). and I tried your suggestion for removing the listner from the destroy and though this will help.

any help is greatly apprciated, like what is the proper callback to use for removing listener in order to remove subscription

Thanks,
Mohammed

To delete a message listener by a callback - this callback needs to be declared first and used in addMessageListener method.

Like:

public static AsyncCallback<String> defaultStringCallback = new AsyncCallback<String>()
{
  @Override
  public void handleResponse( String s )
  {
    System.out.println( "Message arrived to Default channel (String): " + s.toString() );
  }


  @Override
  public void handleFault( BackendlessFault backendlessFault )
  {
    System.out.println("Error in default string-callback: " + backendlessFault.getDetail() );
  }
};

Set as an argument when adding a listener:

channelDefault.addMessageListener( defaultStringCallback );

And to remove a listener just path this callback as an argument:

channelDefault.removeMessageListener( defaultStringCallback );

Regards Anton

Hi Anton,

My ask is how to unsubscribe from a channel. I read the documents of backendless and tried removelistner and still getting error {message=Reached Limit: you can not have more then 5 subscriptions per one connection, code=0, details={limit=5}}’, detail: ‘null’, extendedData: ‘{}’ after 5 calls to the chat fragment (please see this post thread for details)

Thanks,
Mohammed

Mohammed,

We’ve checked all available in SDK listeners deletion methods and all of them work fine. The problem is accumulation of listeners when navigating to ChatRoomActivity in your case. In onCreate() of this activity a listener is added. OnDestroy() method in Android does not guarantee that it will be called when you leave the activity. Please see the Android documentation: https://developer.android.com/guide/components/activities/activity-lifecycle

You may try adding onStop() / onPause() methods and delete listeners there.

Anton

Anton,

You are the best. I tried it in the OnStop() and it works. Thanks a lot

Mohammed