Skip to content

Data/File Paging

Data paging in Backendless 3 is built into the collection returned from the data retrieval operations. Version 5 changes the mechanism by shifting paging operations to the data query class. See the examples below:

Version 3.x

Consider the following data table in Backendless:

sample-data-paging.zoom50
The code for retrieving the data using default page size (10 objects):

final AsyncCallback<BackendlessCollection<Map>> callback = 
    new AsyncCallback<BackendlessCollection<Map>>()
    {
      @Override
      public void handleResponse( BackendlessCollection<Map> restaurantCollection )
      {
        if( restaurantCollection.getCurrentPage().size() != 0 )
        {
          printRestaurants( restaurantCollection.getCurrentPage() );
          restaurantCollection.nextPage( this );
        }
        else
        {
          Log.i( "MYAPP", "Reached the end of collection" );
        }
      }

      @Override
      public void handleFault( BackendlessFault fault )
      {
        Log.e( "MYAPP", "Server reported an error " + fault.getMessage() );
      }
    };

Backendless.Data.of( "Restaurant" ).find( callback );

private static void printRestaurants( List<Map> restaurantsCollection )
{
  Log.i( "MYAPP", "Loaded " + restaurantsCollection.size() +
                  " restaurants in the current page" );

  for( Map restaurant : restaurantsCollection )
    Log.i( "\t" + restaurant.get( "name" ) );
}
The code produces the following output:
Loaded 10 restaurants in the current page  
  Artin's Grill  
  Istanbul  
  Magic Wok  
  Olive Garden  
  Platia  
  Cantina Loredo  
  Wendy's  
  Chili's  
  Kenny's Burgers  
  Tony Roma's  
Loaded 1 restaurants in the current page  
  McDonnald's  
Reached the end of collection

Version 5.x

Identical to the screenshot from 3.x above, consider the following data in version 5 of Backendless:

final DataQueryBuilder queryBuilder = DataQueryBuilder.create();

final AsyncCallback<List> callback = new AsyncCallback<List<Map>>()
{
  @Override
  public void handleResponse( List<Map> restaurantCollection )
  {
    if( restaurantCollection.size() != 0 )
    {
      printRestaurants( restaurantCollection );
      queryBuilder.prepareNextPage();
      Backendless.Data.of( "Restaurant" ).find( queryBuilder, this );
    }
    else
    {
      Log.i( "MYAPP", "Reached the end of collection" );
    }
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
     Log.e( "MYAPP", "Server reported an error " + fault.getMessage() );
  }
};

Backendless.Data.of( "Restaurant" ).find( callback );

private static void printRestaurants( List<Map> restaurantsCollection )
{
  Log.i( "MYAPP", "Loaded " + restaurantsCollection.size() +
                  " restaurants in the current page" );

  for( Map restaurant : restaurantsCollection )
    Log.i( "\t" + restaurant.get( "name" ) );
}
The code produces the same output as the code for 3.x