table not updating in parse - android

I am trying to run a function to update some data in an existing table in parse.com. Below is the function:
private void saveMeToDBnCloud(final LocModel aLocObj)
{
db.addLoc(aLocObj);
ParseQuery<ParseObject> query = ParseQuery.getQuery("tblxxx");
query.getInBackground(myIdInCLoud, new GetCallback<ParseObject>() {
public void done(ParseObject upObj, ParseException e) {
if (e == null)
{
upObj.put("lat", "1");
upObj.put("lng", "2");
upObj.put("geoTime", "3");
upObj.saveInBackground();
Log.d("svcloud","inside func::");
}
else
{
Log.d("svcloud","error::" + e);
}
}
});
}
Note: all columns in the table are String type.
The function is getting called and also getting inside if condition, as its showing the log. But data isn't updating in parse.com.
Any solutions?

SOLVED!!
Just wrote the access permission to write for ACL and its working fine. :-)

Related

Add new row in Parse class using Android

Can't create a new row in using Parse in android. I am able to retrieve, but when I try to add a new row like this, I keep getting false and new row is not being created.
What am I doing wrong here ?
I am exactly following what is given in Parse-Android documentation.
ParseObject storyActivity = new ParseObject("StoryActivity");
storyActivity.put("createdByUser", user);
storyActivity.put("story", story);
storyActivity.put("type", likeUnlike);
return storyActivity.saveInBackground().isCompleted();
Check class level permission Write under class StoryActivity's Security on console.
Call that in following way -
ParseObject storyActivity = new ParseObject("StoryActivity");
storyActivity.put("createdByUser", user);
storyActivity.put("story", story);
storyActivity.put("type", likeUnlike);
storyActivity.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
// your object is successfully created.
} else {
//error occurred
Toast.makeText( context,e.getMessage().toString(),Toast.LENGTH_LONG );
}
}
});
So, by this toast message you can know what is reason of problem you are getting.
Try on this way to set read write permission when user insert/ update record in parse database like ...
ParseObject storyActivity = new ParseObject("StoryActivity");
storyActivity.put("createdByUser", user);
storyActivity.put("story", story);
storyActivity.put("type", likeUnlike);
// here first set read write permission like ..
// when user update value ya insert new value in database
ParseACL postACL = new ParseACL(ParseUser.getCurrentUser());
postACL.setPublicReadAccess(true);
postACL.setPublicWriteAccess(true);
storyActivity.setACL(postACL);
storyActivity.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// success
} else {
// fail
Log.e("Tag", "getting to fail " + e.getMessage());
}
}
});

Android - Parse - deleteInBackground, record not being deleted

I'm using Parse with Android in order to sync my data.
I'm trying to delete an object which is stored in the Parse cloud via
The callback returns and there's no exception, the Logcat message is "deleted".
But the object still exists in table when I check the Parse Data.
tastToEdit is an object from Task class (configured locally in my app).
ParseObject parse_task = new ParseObject("Task");
parse_task.put("Description",tastToEdit.getDescription());
parse_task.put("DueDate",tastToEdit.getDueDate());
parse_task.put("Priority",tastToEdit.getPriority().ordinal());
int com_state = (tastToEdit.getCompleted()) ? 1 : 0;
parse_task.put("IsCompleted",com_state);
parse_task.put("Location",0);
parse_task.put("Category",tastToEdit.getTask_catg().ordinal());
parse_task.put("Status", tastToEdit.getTask_sts().ordinal());
//parse_task.deleteInBackground();
parse_task.deleteInBackground(new DeleteCallback() {
public void done(ParseException e) {
if (e == null) {
Log.d("msg","deleted");
} else {
Log.d("msg", "not deleted");
e.printStackTrace();
}
}
});
What might be causing the callback to return as "deleted" but the object still remains?
Thanks in advance.
You are creating a new ParseObject and you try to delete it after but you don't provide an ObjectID.
A better way to do this will be to first do a ParseQuery for that task you are looking and the in the completion delete it.

Storing/Getting values in Parse

I'm using Parse as my back-end solution and I now need to store some booleans to the server and retrieve them as well.
I have created a ParseObject:
public ParseObject prefs = new ParseObject("Prefs");
and I stored it like this:
prefs.put("setting1", true);
and saved in background:
prefs.saveInBackground();
but when I try to use the bool after retrieving it simply like this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Prefs");
query.getInBackground(prefs.getObjectId(), new GetCallback<ParseObject>() {
#Override
public void done(ParseObject parseObject, ParseException e) {
if(e==null){
if(parseObject.getBoolean("setting1")){
//Do something
}
} else{
utils.toast_error("Check your internet connection");
Gdx.app.log("PARSE", "Some "+e.getCode());
}
}
});
it doesn't return true, instead it returns it core value false.
Have I missed a step or something? Is there more to retrieving data than what I've tried?
Are sure to use the getInBackground method to retrieve the ParseObject?
This could be useful:
https://www.parse.com/docs/android/guide#subclasses

my query.findInBackground not getting executed in android

I am using parse for my data in android app. for some reason the code inside query.findInBackground is not getting executed.
public List<Date> sessionHeaderFetch(){
Log.d("test", "session fetch entry");
ParseQuery<Sessions> query = ParseQuery.getQuery(Sessions.class);
final List<Date> sessionHeaders = null;
query.findInBackground(new FindCallback<Sessions>() {
#Override
public void done(List<Sessions> sessionsObjects, com.parse.ParseException e) {
Log.d("test", "session internal entry");
if (e == null) {
Log.d("test", "Retrieved " + sessionsObjects.size() + " sessions");
for (Sessions session : sessionsObjects) {
sessionHeaders.add(session.getNetsDate());
};
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Log.d("test", "session last value");
return sessionHeaders;
}
the code inside public void done() is not all invoked.
I don't think you have understood how to query correctly in Parse.
When you define the parse query. The get query should contain the name of the table that you are trying to query. Also the queries returned will be ParseObjects normally, so I would expect that your callback should be new FindCallback().
I've adjusted the parse query below.
ParseQuery<Sessions> query = ParseQuery.getQuery("ParseTableName");
final List<Date> sessionHeaders = null;
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> sessionsObjects, com.parse.ParseException e) {
Log.d("test", "session internal entry");
if (e == null) {
// Find succeeded, so do something
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Obviously you will need to replace "ParseTableName" with the name of the table that you are trying to query in parse.
I actually solved it by using an ArrayList, there were some problems with the List initialization and also the results are fetched asynchronous manner so my functions which calls these functions were getting null values so I had to write by calling functions that calls the parse fetch functions asynchronously as well.
but the query can be written like this and it works.
public void sessionFetch(Date headers, final ParseIOListener<Sessions> listener){
ParseQuery<Sessions> query = ParseQuery.getQuery(Sessions.class);
Log.d("test", "input header" + headers );
query.whereEqualTo("NetsDate",headers);
final ArrayList<Sessions> sessionsData = new ArrayList<Sessions>();
query.findInBackground(new FindCallback<Sessions>() {
#Override
public void done(List<Sessions> sessionsObjects, com.parse.ParseException e) {
if (e == null) {
for (Sessions session : sessionsObjects) {
Log.d("test", "output objects" + session.toString() );
sessionsData.add(session);
Log.d("test", "Retrieved -- sessions" + sessionsObjects.size() );
}
listener.onDataRetrieved(sessionsData);
} else {
listener.onDataRetrieveFail(e);
}
}
});
}
If you want more details on implementing this, check this link
The reason why you feel the code is not being invoked is because you are returning from the method before the ".findInBackground" operation has completed. Remember the query is performed on a background thread. So this is how your code will run:
ParseQuery query = ParseQuery.getQuery(Sessions.class);
final List sessionHeaders = null;
------> 1. query.findInBackground (Popped onto background thread)
return sessionHeaders; (by the time you get here, sessionHeaders will probably still be null).
So change the logic of the code and wait till the callback returns before doing any processing on the "sessionHeaders" object.

How to get latest updated parse object in android?

I don't know about parse and I want to learn it.I want to know how can I get the latest updated parse object in parse.I tried to use get first in background but I think there is a problem in my ParseQuery.Please provide me the right way of query to get the latest object I just pushed on the parse cloud back.
ParseQuery<ParseObject> query=ParseQuery.getQuery("RBSE");
query.whereEqualTo("roomA","900");
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject objectLatest, ParseException e) {
if(e==null){
}
else{
}
}
}
To get the most recently created/modified, simply sort descending by the "updatedAt" field (it is built-in).
ParseQuery<ParseObject> query = ParseQuery.getQuery("RBSE");
query.orderByDescending("updatedAt");
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("RBSE", "The getFirst request failed.");
} else {
// got the most recently modified object... do something with it here
}
}
});

Categories

Resources