How to search data in Back4app - android

I'm creating an application on android, and I'm using back4app as my back end. How to search data from back4app using Android Search View?
Thanks in Advance...

at the moment I believe that the structure below can help you, it's just a example :)
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.whereEqualTo("playerName", "Dan Stemkoski");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});

Related

Not able to fetch data from parse.com

I am using the Parse SDK for Android. I am not able to retrieve the data I stored in the cloud. I stored it manually using the Parse dashboard by creating a class called "Average" and creating a few rows. One of the columns is "squarefeet".
I want to retrieve the object whose "squarefeet" equals the value stored in the variable area.
What am I doing wrong? The compiler doesn't execute the done(params..) method. Below is the code.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Average");
query.whereEqualTo("squarefeet", area);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objList, ParseException e) {
if (e == null) {
if (objList.size() > 0) {
for (int i = 0; i < objList.size(); i++) {
ParseObject p = objList.get(i);
averageConsumption = p
.getNumber("average_consumption");
efficientConsumption = p
.getNumber("efficient_consumption");
}
}
} else {
//something went wrong!
}
}
});
Use this
int area=120;
ParseQuery<ParseObject> query = ParseQuery.getQuery("Average");
query.whereEqualTo("squarefeet", area);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});

How to read data from ParseObject in Android

I'm new to Parse.com and Android and I'm struggling to read data from a Parse Object. I read the documentation and downloaded the tutorials but it is not clear. I have a ParseObject named Issue and all I need is to read data from this object and display it to the user. Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_issue);
Parse.enableLocalDatastore(this);
Parse.initialize(this, "QKpM7ar7aWwrbEeTcrSGJ5bDnLMCUtc1kCr26Enl", "MCBdIQ6Y0dTsIoahzJ44UfR1zHZPJMQPwiETwj47");
ParseQuery<ParseObject> query = ParseQuery.getQuery("Issue");
query.whereEqualTo("objectId", "2aRwvd1Rnv");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> issueList, com.parse.ParseException e) {
if (e == null) {
Log.d("Issue", "Retrieved " + issueList.size() + " issue");
Toast.makeText(getApplicationContext(), "List" + issueList, Toast.LENGTH_LONG).show();
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
}
I don't understand how I can read data from this ParseObject. The returned result issueList is this: List[com.parse.ParseObject#4b079f88]
And if I use issue.getString("objectId") I get an error. Please help.
Thanks to Mr. Shubendara I was able to fix this:
if (issueList!=null){
if (issueList.size()>0){
for( int i = 0; i<issueList.size(); i++){
String o = issueList.get(i).getString("Title");
Toast.makeText(getApplicationContext(), "List" + o, Toast.LENGTH_LONG).show();
}
}

Android Parse Query

I'm using the following iOS Parse query:
let predicate = NSPredicate(format: "(fromUserid = %# OR fromUserid = %#) AND (toUserid = %# OR toUserid = %#) AND seen = %#", profilePhotoID, friendProfilePhotoID, profilePhotoID, friendProfilePhotoID, false)
var query = PFQuery(className: "Message", predicate: predicate)
How can I do the same query using the Parse Android SDK? I don't see an option to do predicates like that.
You can query data from parse in android SDK is like given example...
ParseQuery<ParseObject> query = ParseQuery.getQuery("Message");
String[] ids = {profilePhotoID, friendProfilePhotoID};
query.whereContainedIn("fromUserid", Arrays.asList(ids));
query.whereContainedIn("toUserid", Arrays.asList(ids));
query.whereEqualTo("seen", false);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("Message", "Retrieved " + scoreList.size() + " Message");
} else {
Log.d("Message", "Error: " + e.getMessage());
}
}
});
For more details please refer Parse Query Document
let me know if anything needed..

Parse android application query: saving retrieved data

I use parse.com to get an Integer, which saves how many gold a user has.
I tried this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("gold");
query.whereEqualTo("username", username);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
//how can I save the gold as an integer?
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
That depends key you used to store the gold in the ParseObject. Once you have that, you can just replace your comment with:
int score = scoreList.get(0).getInt(<keyForGold>);

How can I retrieve all the groups name from server on parse.com in android?

I am facing a big problem in parse api. I am able to create new group on server as well able to add user to the group also. I created many group on server like Friends, Sports, College etc. But how can I retrieve the names of all group from server?
Using the below code I can retrieve all the user in the group.
public void getUserList() {
String groupName="Friends"
final ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
ParseRelation relation = currentUser.getRelation(groupName);
ParseQuery query = relation.getQuery();
try {
Log.e("Size ", "Size " + query.count());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// query.whereEqualTo("username", null);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException arg1) {
// TODO Auto-generated method stub
try {
for (int i = 0; i < objects.size(); i++) {
ParseObject r = objects.get(i);
String name = r.getString("username").toString();
Log.e("user name ", "===>" + name);
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Error : " + e.toString(), 1).show();
}
}
});
}
}
In above screen-shot I need all the names like Friends, MYGroup and xyz using one query.
Please help me.
To get all groups, you need to query the Group class (or whatever you have called it):
ParseQuery<ParseObject> query = ParseQuery.getQuery("Group");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> groupList, ParseException e) {
if (e == null) {
for (ParseObject group : groupList) {
Log.d("group", "Group name: " + group.get("name");
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});

Categories

Resources