Support Topics Documentation Slack YouTube Blog

difference between push notification and pub/sub

I am using synchronous API call and still getting this error

There could be many other reasons for the error, but the root cause is that you’re doing something wrong when using the API

I’ll post my code here

QueryOptions queryOptions = new QueryOptions();
queryOptions.addSortByOption("ascending");
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setPageSize(100);
BackendlessCollection<Messages> collection = Backendless.Persistence.of(Messages.class).find(dataQuery);
if (collection != null) {
    while (collection.getCurrentPage().size() > 0) {
        //int size = collection.getCurrentPage().size();
        UsersMessages = collection.getCurrentPage();
        messagesAdapter adapter = new messagesAdapter(MainActivity.this, UsersMessages);
        listView.setAdapter(adapter);
        collection.nextPage();
    }
    swipeRefreshLayout.setRefreshing(false);
}else {
    swipeRefreshLayout.setRefreshing(false);
}

Please tell me what is the wrong in this code !

You must use async API when calling method from the main thread. Sorry, it was a typo in my earlier message.

Then what I have to do now ? Using another thread ?

Either create another thread and call sync API there. Or see the doc for the async calls and use them in the main thread.

The problem is that I haven’t understand when to use nextPage method with async API call if I want to update listview

It depends on how the UI works. If there is a link/button to get the next “page” of data, you could call it when the user clicks the link/button.

Yeah this is a great Idea … I haven’t think like that … but what if there is only one page ?

The response contains property “totalObjects”. If the combined size of all loaded pages equals that number, then there is no more pages to load.

I’ve set the page size to 100 … with if statment :

if(response.totalObjects() > 100){
response.nextPage
UsersMessages = collection.getCurrentPage();
messagesAdapter adapter = new messagesAdapter(MainActivity.this, UsersMessages);
listView.setAdapter(adapter);
}
this should work right ?

this line does not look like correct code:

response.nextPage

There is a working example which I pointed out at the very beginning of this discussion. I know that the example works. If you need us help you with writing your client app, this could be done on the consulting services basis, but we really can’t assist with client development app through support. Support for helping with server-side API.

If you have a specific question about paging, you are welcome to ask. How to write a client app, this would be outside of what we can do through support. There are plenty of examples we posted which you should look through and see how it is done.

ok I’ve solved the problem thank you