cancel subscription

i use bellow code to be subscriber in android, everything is good. but after about 5 seconds i need check if there is no message, cancel request and alarm to user :“nothing received…”. but backendless option for cancel subscription not good for me. how do this?

SubscriptionOptions mSubscriptionOptions = new SubscriptionOptions();
Backendless.Messaging.subscribe(“channel1”, new AsyncCallback<List<Message>>() {
public void handleResponse(List<Message> response) {
Log.i(getTag(), response.toString());

        public void handleFault(BackendlessFault fault) {
            Log.e(getTag(), fault.getMessage());
    mSubscriptionOptions, new AsyncCallback&lt;Subscription&gt;() {
        public void handleResponse(Subscription response) {
            Log.e(getTag(), response.toString());
            Subscription mSubscription = response;

        public void handleFault(BackendlessFault fault) {
            Log.e(getTag(), fault.getMessage());


As I understand you want to cancel a subscription if there are no messages after 5 seconds, Am I right?
So why using our API (subscription.cancelSubscription()) for that isn’t good for you?
or maybe I don’t full understand your question

Regards, Vlad

hi again,
thanks, you understand my question very well.

YOU: So why using our API (subscription.cancelSubscription()) for that isn’t good for you?

my answer: because i dont know how set time (5 seconds) and after that run CANCEL command.
please send me full example that where i put specific time …

Other question: is it possible to cancell any or all backendless requests in android. Assume a case that in a fragment i send some different requests to backendless and user suddenly click back button and does not wait for responses, So i do not need those response any more, then i want to cancel all or some specific requests to backendless. this problem occurs because requests are async and still alive when back button pressed. may be you say what is the problem because all responses finish in a specific time. I say assume user click back button and again come back to that fragment over and over again, so requests goes over and over again and my network and app will be down. help me please. thanks again.

Hi Morteza

Regarding your last question - if the request has already been sent to server there is now way to cancel it. As for the initial question - try this solution


Thanks a lot,
i know can not cancel request when send it to server, i mean i want to cancel reception or i do not want my app get response of sent request, i do not know how.

then, i know how do some things after some seconds, my problem is what is appropriate code in that thread that i need, because subscription object that i want call Cancelation on it, is discoverable just in sent request not every where that i need.

i hope so my bad English writing does not nervous you!!!


Before calling subscription method you’ll need to declare a variable (boolean or List<Message>). In handleResponse block of your subscription method change the variable state (to true if bool, or set response value to the List<Message> variable). After subscription method run a handler with an IF condition:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
 public void run() {
 if( messagesReceived==true ) {
}, 5000);

For your consideration in future - Backendless support forum is for managing Backendless related questions. “How To” Java questions should be rather asked at Reference for free support policy -