Without knowing what is in the table, but only knowing the name of the Backendless table and column, how can Android app fetch data from Backendless table?
Yes, please see the examples in the docs:
https://backendless.com/docs/android/doc.html#data_basic_search
Thanks.
I created a Backendless app called Contact, then I used codeGen to make a download zip. I opened the zip and opened file in Android Studio. However, it failed to run on my phone and on the emulator with Nexus 5.
I want to use the example code in class Contact and the asynchronous method saveNewContact() to learn how to save info to a table in Backendless.
(Contact class in https://backendless.com/docs/android/doc.html#data_basic_search)
Can you provide more details on the failure to run?
I managed to save data into Backendless table, now I am trying to retrieve that data. I don’t understand how.
The following code has compile errors, but shows what I am trying to do.
package com.examples.contact;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.backendless.Backendless;
import com.backendless.BackendlessUser;
import com.backendless.IDataStore;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.DataQueryBuilder;
import java.util.List;
import java.util.Map;
public class FindContactActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.find_contact);
Backendless.setUrl( Defaults.SERVER_URL );
Backendless.initApp( getApplicationContext(), Defaults.APPLICATION_ID, Defaults.API_KEY );
}
void onFindContact() {
IDataStore<Map> contactStorage = Backendless.Data.of( "Contact" );
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
// set where clause
queryBuilder.setWhereClause( "age < 30" );
// set related columns
queryBuilder.setRelated( "address", "phoneNumber" );
// request sorting
queryBuilder.setSortBy( "name" );
//set offset and page size
queryBuilder.setPageSize( 20 );
queryBuilder.setOffset( 40 );
contactStorage.find( queryBuilder, new AsyncCallback<List<Map>>()
{
@Override
public void handleResponse( List<Map> contactObjects )
{
Log.i( "MYAPP", "Retrieved " + contactObjects.size() + " objects" );
Toast.makeText(FindContactActivity.this,"Retrieved " + contactObjects.size() + " objects from Backendless table", Toast.LENGTH_LONG).show();
BackendlessUser user = Backendless.UserService.CurrentUser();
if( user != null )
{
// get user's phone number (i.e. custom property)
String phoneNumber = (String) user.getProperty( "phoneNumber" );
Toast.makeText( FindContactActivity.this, String.format( "phone number: %s", phoneNumber ), Toast.LENGTH_LONG ).show();
// get user's age (i.e. custom property)
String age = (String) user.getProperty( "age" );
Toast.makeText( FindContactActivity.this, String.format( "age: %s", age ), Toast.LENGTH_LONG ).show();
// get user's adress (i.e. custom property)
String adress = (String) user.getProperty( "adress" );
Toast.makeText( FindContactActivity.this, String.format( "adress: %s", adress ), Toast.LENGTH_LONG ).show();
}
@Override
public void handleFault( BackendlessFault fault )
{
//Log.e( "MYAPP", "Server reported an error " + fault.getMessage );//compile error at 'getMessage'
Toast.makeText(FindContactActivity.this,"Backendless Server reported an error ", Toast.LENGTH_LONG).show();
}
});
//</Map> //compile error at '</map>'
}
}
If you could provide details on the actual compiler errors, it would help us help you locate the problem…