0
Android應用程序用戶數據已保存到Backendless表中。我想從表中檢索用戶數據。Backendless Android:如何從表中檢索特定的用戶數據?
我試着用where子句搜索,但我不知道如何顯示找到的數據。 https://backendless.com/docs/android/doc.html#data_search_with_where_clause
下面的代碼有Backendless服務器錯誤1023
void onFindContact() {
IDataStore<Map> contactStorage = Backendless.Data.of("Contact");
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
// set where clause
queryBuilder.setWhereClause("age is not null");
// 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 address (i.e. custom property)
String adress = (String) user.getProperty("address");
Toast.makeText(FindContactActivity.this, String.format("address: %s", adress), Toast.LENGTH_LONG).show();
}
}
@Override
public void handleFault(BackendlessFault fault)
{
Log.e("MYAPP", "Server reported an error " + fault.getCode());//compile error at 'getMessage'
Toast.makeText(FindContactActivity.this,"Backendless Server reported an error "+ fault.getCode(), Toast.LENGTH_LONG).show();
}
});
//</Map> //compile error at '</map>'
/**** from https://backendless.com/docs/android/doc.html#data_search_with_where_clause
* Find all contacts where the value of the "age" property equals 47:
*
String whereClause = "age = 47";
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);
Backendless.Data.of("Contact").find(queryBuilder, new AsyncCallback<List<Map>>(){
@Override
public void handleResponse(List<Map> foundContacts)
{
// every loaded object from the "Contact" table is now an individual java.util.Map
}
@Override
public void handleFault(BackendlessFault fault)
{
// an error has occurred, the error code can be retrieved with fault.getCode()
}
});
*/
}
}
你能提供什麼你示例代碼到目前爲止嘗試過嗎? – Submersed
o&鏈接到你正在談論的一些文檔 – Blundell
我試着在https://backendless.com/docs/android/doc.html#data_search_with_where_clause上使用'where子句'的例子 – bryonss