How to retrieve all rows of ParseObject in Android - android

On googlemap if my app user creates any maker I am storing that marker location details as a parse object,
now I want to retrieve all location details of all markers, how to do it. I already gone through parse.com tutorial links.

Try something like....
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("GreenMarkers");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> markers, ParseException e) {
if (e == null) {
// your logic here
} else {
// handle Parse Exception here
}
}
});
This should get all items from the "GreenMarkers" table.

Related

Query inside for loop in Back4App(Parse)

I am building a social network application using parse which have follow/unfollow feature.
I have two tables: Users and Follow table.
Users table have user related data and Follow table have two fields: followerId and followedId.
I have a list of searched users. So, corresponding to each user i just want to get from query that whether i am following him/her or not. So, how to run query inside a loop?
Any help will be deeply appreciated.
Thanks.
For get follower
ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followedId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
public void done( List<ParseObject> MyList, ParseException e) {
if (e == null) {
// Get your follower user list
}else{
//error
}
For get following
ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followerId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
public void done( List<ParseObject> MyList, ParseException e) {
if (e == null) {
// Get your following user list
}else{
//error
}
Then after call user list query in ParseUser table and get all the user.
Thanks

Parse.com android app case insensitive searches

I'm using parse backend for one of my apps. There are three tables and I want to be able to search text entered by the user in search view in the table columns.
private void getDataFromParse() {
ParseQuery<ParseObject> query = ParseQuery.getQuery(Message.NAME);
query.addDescendingOrder(Message.CREATED_AT);
**query.whereStartsWith(Message.MESSAGE, mTag);**
query.setLimit(20);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
mMessages = (List<Message>) (Object) objects;
setAdapter();
}
}
});
}
The problem is that parse search is case sensitive. I enter the table content in parse from their websites UI. One suggestion to solve this problem is here
http://blog.parse.com/learn/engineering/implementing-scalable-search-on-a-nosql-backend/
How do solve my problem ?
You can convert the text enterd by the user to upper case and make sure that all the data in parse are upper case too

Check for username's existence | Parse.com

I'm searching for a good way of querying usernames towards my app's user-database. So that people can't signup with the same username as someone else.
I'm using a username, password and an email for recover of password. So I want to check for username's basically.
I've understood this can be achieved with ParseQuery?
I would like an example if anyone can provide?
You can use a ParseQuery to query all usernames in the database like this.
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
// objects is a list of all the User you have. Just get all the usernames,
//and check if there's already one equal to the one you want to insert.
} else {
//error handling
}
}
}

Android. Parse.com: array is not updating

On every launch my app loads fresh data from parse.com and pins all objects to use app without network requests like this^
public void pinKids() {
ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseConstants.CLASS_KIDS);
query.whereEqualTo(ParseConstants.KEY_PARENT, currentUser);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(final List<ParseObject> kidsList, ParseException e) {
if (e == null) {
ParseObject.unpinAllInBackground(ParseConstants.LABEL_KIDS, new DeleteCallback() {
#Override
public void done(ParseException e) {
ParseObject.pinAllInBackground(ParseConstants.LABEL_KIDS, kidsList, new SaveCallback() {
#Override
public void done(ParseException e) {
Log.d("Hello", "pinKids");
}
});
}
});
}
}
});
}
One of the columns in my class is an array of strings (it stores history messages). I found that my code doesn't refresh this array if that array was updated from the other device (the same user did something on the other device). The rest of the data (other columns) refresh without problems. But the array of strings stays as it was downloaded at first launch.
In parse.com dashboard I see that array is updated. But code doesn't download this array while all the other columns are downloaded correctly.
Let me say that when I update this array on device-1 the new data is stored on device-1 and on "parse.com" too. But it doesn't update on device-2.
Please help!
OK! I've solved it.
This problem is a bug of parse.com.
I've created an issue on parse's github.
So I found that my problem is a part of parse's bug.
So the answer is: replace all calls to getJSONArray(key) with getList(key). You might also need revert()/revert(key)

Not getting list of parse object I am fetching from parse

I am using this code for getting a row from the parse cloud but everytime I am fetching objects it is giving me empty list,Although there is a corresponding row available in the parse which I am trying to find and update.
public void onClick(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentInfo");
query.whereEqualTo("rollnum",rollnum.getText().toString());
query.whereEqualTo("name",name.getText().toString());
query.whereEqualTo("city",city.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if(e == null && objects.size() > 0){
obj=objects.get(0);
obj.put("rollnum",rollnum.getText()
.toString());
obj.put("name",name.getText().toString());
obj.put("city", city.getText().toString());
obj.saveInBackground();
}
else if(objects.size()==0){
Toast.makeText(getApplicationContext(), "No relation Found!"+e,Toast.LENGTH_LONG).show();
}
}
}
If the object is there I am updating it with new values with help of put method.But it is always giving me an empty list of Parse Objects.
I think you are trying to update the available objects.You can do it this way.
public void onClick(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentInfo");
query.whereEqualTo("rollnum",rollnum.getText().toString());
query.whereEqualTo("name",name.getText().toString());
query.whereEqualTo("city",city.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if(e == null ){
if(object.size()==0){
//here you can put object with help of put method if object is not there and when the object size is greater than 1 you remove the other objects except the objects.get(0).All other objects except one will be removed and only the zeroth object will be updated at the time user updates it
}
else if( objects.size() > 0){
obj=objects.get(0);
obj.put("rollnum",rollnum.getText()
.toString());
obj.put("name",name.getText().toString());
obj.put("city", city.getText().toString());
obj.saveInBackground();
}
}
else{
//exception in getting data
}
}
}
If you are getting a empty list of objects then that means there are no objects stored that match the criteria that you are querying against.
Make sure you understand your query. The way you are setting up your query, there has to be a ParseObject stored where the rollnum, name, and city are equal to those values you are testing against, and they must be exactly equal. If no objects match that criteria, then parse will return an empty list. Use the Logcat and Parse Dashboard to debug and find out what's wrong with your query.

Categories

Resources