ParseObject not updated after trying to update/sve it in android - android

I am trying to retrieve a row in my table on parse. I found the objectId, but when I try to update the row with new information, nothing happens. Any help would be appreciated. Thanks!
mSaveAndNextSteps.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ParseQuery<SingleFactInfo> query = ParseQuery.getQuery("Fact_Info");
query.getInBackground(mEventObjectId, new GetCallback<SingleFactInfo>() {
public void done(ParseObject fact, ParseException e) {
if (e == null) {
// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the Parse Cloud. playerName hasn't changed.
fact.add("factDescriptiontwo", mEventDescription.getText().toString());
event.put("factDescription", mEventDescription.getText().toString());
event.saveInBackground(new SaveCallback() {
#Override
public void done(com.parse.ParseException e) {
}
});
}
}
#Override
public void done(SingleFactInfo parseObject, com.parse.ParseException e) {
Intent goToFactLists = new Intent(CreateEventSectionTwo.this, EventList.class);
startActivity(goToFactLists);
}
});
}
});

So here is the working solution that worked for me. Queried the object using objectId, then updated it in the 'done' section.
mSaveAndNextSteps.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ParseQuery<SingleFactInfo> query = new ParseQuery("Event_Info");
query.getInBackground(mEventObjectId, new GetCallback<SingleFactInfo>() {
public void done(ParseObject event, ParseException e) {
if (e == null) {
// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the Parse Cloud. playerName hasn't changed.
Toast.makeText(getApplicationContext(), mYourEditText.getText().toString(), Toast.LENGTH_LONG).show();
}
}
#Override
public void done(SingleFactInfo parseObject, com.parse.ParseException e) {
parseObject.put("eventDescription", mYourEditText.getText().toString());
parseObject.saveInBackground();
Intent goToFactsList = new Intent(YourApplication.this, EventList.class);
startActivity(goToFactsList);
}
});
}
});

Related

How to update Message Activity without refresh?

I am making app where users can chat with each other in app , but the problem is when user send message it doesn't appear in chat box until user refresh the activity . how can i update chat without refresh ?
this is my code
ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class);
subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<Message>() {
#Override
public void onEvent(ParseQuery<Message> query, final Message message) {
// HANDLING create event
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
mList.add(message);
msgAdapter.notifyDataSetChanged();
show_message.scrollToPosition(mList.size() - 1);
}
});
public void onEvent(ParseQuery<Message> query, Message message) {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
mList.clear();
getData();
}
});
public void onClick(View v) {
Message msg = parseMessenger.SendMessage(send_txt.getText().toString(), null, new SaveCallback() {
#Override
public void done(ParseException e) {
send_txt.setText("");
}
}, new SendCallback() {
#Override
public void done(ParseException e) {
}
});
if (mList == null) {
mList = new ArrayList<Message>();
}
}
});
getData();
private void getData() {
ParseQuery<Message> messageFromQuery = Message.getAllMessage();
messageFromQuery.whereEqualTo(Message.COL_USER_FROM, userFrom);
messageFromQuery.whereEqualTo(Message.COL_USER_TO, userTo);
ParseQuery<Message> messageToQuery = Message.getAllMessage();
messageToQuery.whereEqualTo(Message.COL_USER_TO, userFrom);
messageToQuery.whereEqualTo(Message.COL_USER_FROM, userTo);
List<ParseQuery<Message>> messageQueries = new ArrayList<ParseQuery<Message>>();
messageQueries.add(messageFromQuery);
messageQueries.add(messageToQuery);
ParseQuery<Message> messageQuery = ParseQuery.or(messageQueries);
messageQuery.orderByAscending("createdAt");
messageQuery.findInBackground(new FindCallback<Message>() {
#Override
public void done(List<Message> messages, ParseException e) {
if (messages != null) {
mList.clear();
mList.addAll(messages);
msgAdapter = new MsgAdapter(requireContext(), mList, userTo.getObjectId(), userTo);
show_message.setAdapter(msgAdapter);
show_message.scrollToPosition(mList.size() - 1);
}
}
});
}
i can add auto refresh when send button is clicked but i don't want so , it will not look nice when users use it .. please help

Parse objects are not deleting

I am using parse as baas , I was using below code to delete objects .But tommorow i came to know that this piece of code is not working .
#Override
public void onClick(View view) {
new AlertDialog.Builder(context).setIcon(R.drawable.main).setTitle("Delete this product ?")
.setMessage("Are you sure you want to Delete this product ?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("VendorInv");
query.whereEqualTo("objectId", details.getObjectId());
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
try {
object.delete(); // fixed part
object.saveInBackground(new SaveCallback() { // fixed part
#Override
public void done(ParseException e) {
if (e == null) {
vendorDetailsList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, vendorDetailsList.size());
count.setText(String.valueOf(vendorDetailsList.size()) + "/" + totalNo + " items are Online");
Toast.makeText(context, "Deleted", Toast.LENGTH_SHORT).show();
}
}
});
} catch (ParseException e1) {
Log.i("sand", e1.toString());
}
}
});
}
}).setNegativeButton("No", null).show();
}
});
}
Then as a contributor of parse android said than i fixed this part of code below
holder.cross.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new AlertDialog.Builder(context).setIcon(R.drawable.main).setTitle("Delete this product ?")
.setMessage("Are you sure you want to Delete this product ?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("VendorInv");
query.whereEqualTo("objectId", vendorDetailsList.get(position).getObjectId());
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
/* this part is changed */ object.deleteInBackground(new DeleteCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("sand", vendorDetailsList.get(position).getObjectId());
vendorDetailsList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, vendorDetailsList.size());
count.setText(String.valueOf(vendorDetailsList.size()) + "/" + totalNo + " items are Online");
Toast.makeText(context, "Deleted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Not Deleted please check your network connection", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}).setNegativeButton("No", null).show();
}
});
Toast is printing deleted but still object is not deleted in database.
I dont know where i am going wrong, but this is not helping me in deleting an object
Any help would be greatly appreciated
Config your class VendorInv on the server to be "Public Read and Write enabled"
and use next code:
ParseQuery<ParseObject> query = ParseQuery.getQuery("VendorInv");
query.getInBackground(vendorDetailsList.get(position).getObjectId(), new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if (object != null) {
object.deleteInBackground(new DeleteCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.i("sand", vendorDetailsList.get(position).getObjectId());
vendorDetailsList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, vendorDetailsList.size());
count.setText(String.valueOf(vendorDetailsList.size()) + "/" + totalNo + " items are Online");
Toast.makeText(context, "Deleted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Not Deleted please check your network connection", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});

Parse Frame Work Update Query does not work

I am using parse frame work in android, I am updating user object in that but I update that old data is replaced with new data here my code is . How to resolve it any one help me solve out it.
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("objectId", currentUser.getObjectId());
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
currentUser.put("forbiddenWords", wordArray);
currentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
hideProgressDialog();
if (e == null) {
Snackbar.make(parentView, R.string.string_setting_chnaged, Snackbar.LENGTH_LONG).show();
} else {
e.printStackTrace();
}
}
});
}
});
I guess you wanna update some value of your current user. Try this code
ParseUser user = ParseUser.getCurrentUser();
user.put("forbiddenWords", wordArray);
user.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
hideProgressDialog();
if (e == null) {
Snackbar.make(parentView, R.string.string_setting_chnaged, Snackbar.LENGTH_LONG).show();
} else {
e.printStackTrace();
}
}
});

Android Parse.com Unable to remove an item from Array field in both installation and User object

I've two array fields in my parse app one in Installation object named as "subscriber" and other in User object named as "SubsUser".
I've been trying to remove an item from both arrays by using this code...
user.getList("SubsUser").remove(item);
user.save();
installation.getList("subscriber").remove(item);
installation.save();
but even after using this code the items are visible on parse dashboard, it seems both my tables are not being updated.
You should use put method to let ParseObject aware data is dirty.
ParseUser user = ParseUser.getCurrentUser();
List<Object> list = user.getList("SubsUser");
list.remove(item);
user.put("SubsUser", list);
user.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Log.d(TAG, "saved in background");
if (e == null)
//ok
else
//something else went wrong
}
});
I myself solved the problem, i was using incorrect code
the write code to remove an object or collection of object from a parse array is
List<String> list=new ArrayList<String>();
list.add(item);
user.removeAll("SubsUser",list);
user.save();
installation.removeAll("subscriber",list);
installation.save();
I have a solution too, with a dialog
final Dialog dialog = new Dialog(activity);
dialog.setContentView(R.layout.dialogo_si_no);
dialog.setTitle("La Lista");
Button btnAceptar = dialog.findViewById(R.id.btnSi);
Button btnCancelar = dialog.findViewById(R.id.btnNo);
TextView lblMensaje = dialog.findViewById(R.id.lblMensaje);
lblMensaje.setText("¿Deseas eliminar este evento de tus favoritos?");
dialog.show();
btnAceptar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
RelativeLayout layout = (RelativeLayout) view.getParent();
TextView lblObjectId1 = (TextView)layout.getChildAt(0);
final String objectId = lblObjectId1.getText().toString();
final ParseQuery<ParseObject> qFavoritos = ParseQuery.getQuery("favoritos").whereEqualTo("usuarioId",sharedpreferences.getString("globalUserId","0"));
try {
List<ParseObject> resultado = qFavoritos.find();
final String id = resultado.get(0).getObjectId();
qFavoritos.getInBackground(id, new GetCallback<ParseObject>() {
#Override
public void done(final ParseObject object, ParseException e) {
if (e == null) {
List<Object> lista = object.getList("eventos");
lista.remove(objectId);
object.put("eventos",lista);
object.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Log.d(TAG, "saved in background");
if (e == null) {
Log.d(TAG, "favorito eliminado");
Intent intent = new Intent(activity, EventosActivity.class);
activity.startActivity(intent);
}else{
Log.d(TAG, e.getMessage());
}
}
});
}else{
Log.d(TAG,e.getMessage());
}
}
});
}catch (Exception ex){
Log.d(TAG,ex.getMessage());
}
}
});
btnCancelar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});

parse.com update data android

I have an object at parse.com in the class Grillen with data.
Now I want to make it such that if I click a button it adds to the row with the same name as selected in a spinner, and it updates the columns Betrag and Rechnung. I tried the following code but it doesn't work.
public void createRechnung(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Grillen")
// Retrieve the object by id
query.getInBackground(String.valueOf(mNameInput), new GetCallback<ParseObject>() {
public void done(ParseObject Grillen, ParseException e) {
if (e == null) {
Grillen.put("Betrag", mBetragInput);
Grillen.put("Rechnung", false);
Grillen.saveInBackground();
}
}
});
}
Use this code to check what's going wrong
ParseQuery<ParseObject> query = ParseQuery.getQuery("Grillen");
// Retrieve the object by id
query.getInBackground(String.valueOf(mNameInput), new GetCallback<ParseObject>() {
public void done(ParseObject Grillen, ParseException eg) {
if (eg == null) {
Grillen.put("Betrag", mBetragInput);
Grillen.put("Rechnung", false);
Grillen.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
//success, saved!
Log.d("MyApp", "Successfully saved!");
} else {
//fail to save!
e.printStackTrace();
}
}
});
}else {
//fail to get!!
eg.printStackTrace();
}
}
});
If you successfully save, then your exception is null, if it didn't you will know why via stacktrace. I suggest running this code and letting the execution flow of the app be based on whether or not the save was successful or not.
Read this: getInBackground(String, callback) You must pass the objectId of the object you are trying to get, rather than the name. Make sure you are getting by ObjectID and not name as it appears you are doing. ObjectId looks like a random string and should be found in your database by looking online on Parse
Do this instead:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Grillen");
query.whereEqualTo("name", String.valueOf(mNameInput));
// Retrieve the object by id
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException eg) {
if (eg == null && objects.size() > 0) {
ParseObject Grillen = objects.get(0);
Grillen.put("Betrag", mBetragInput);
Grillen.put("Rechnung", false);
Grillen.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
//success, saved!
Log.d("MyApp", "Successfully saved!");
} else {
//fail to save!
e.printStackTrace();
}
}
});
}else {
//fail to get!!
eg.printStackTrace();
}
}
});
Note: I have no idea what the column name is for the 'name' attribute of Grillen objects, so you might need to change this to whatever you call the name column for that object.
Okay i have get the Spinner to work for the name but not the EditText
here is some part of the codes
public class RechnungActivity extends AppCompatActivity {
private EditText mBetragInput;
private Spinner mNameInput;
private String mName;
private String mBetrag;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechnung);
ParseObject.registerSubclass(Grillen.class);
mBetragInput = (EditText) findViewById(R.id.Sonstiges);
mNameInput = (Spinner) findViewById(R.id.Name);
mName = mNameInput.getSelectedItem().toString();
mBetrag = mBetragInput.getText().toString();
}
public void createRechnung(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Grillen");
query.whereEqualTo("name", mName);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException eg) {
if (eg == null && objects.size() > 0) {
mBetrag = mBetragInput.getText().toString();
ParseObject Grillen = objects.get(0);
Grillen.put("Betrag", mBetrag);
Grillen.put("Rechnung", true);
Grillen.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
//success, saved!
Log.d("MyApp", "Successfully saved!");
} else {
//fail to save!
e.printStackTrace();
}
}
});
}else {
//fail to get!!
eg.printStackTrace();
}
}
});
}

Categories

Resources