The parse android documentation states this:
Objects can have relationships with other objects. To model this behavior, any ParseObject can be used as a value in other ParseObjects. Internally, the Parse framework will store the referred-to object in just one place, to maintain consistency.
What I understand by this is when I do this for put :
firstObject =new ParseObject("A");
secondObject= new ParseObject("B");
secondObject.put("A",firstObject);
According to the last line of the blockquote, this means that the object is not created in B, it simply stores a pointer in B (for A)
Now this createwithoutdata:
You can also link objects using just their objectIds like so:
// Add a relation between the Post with objectId "1zEcyElZ80" and the comment
myComment.put("parent", ParseObject.createWithoutData("Post", "1zEcyElZ80"));
This also means that a pointer is used in place of the object, right?
What is the difference between put and createwithoutdata and what are the usecases where you use each one?
EDIT:
ParseObject parseObject=new ParseObject("TestClass");
ParseObject parseObject1=new ParseObject("TestObject");
parseObject.put("ps1",ParseObject.createWithoutData("TestObject",parseObject1.getObjectId()));
parseObject.saveEventually();
In this each time a new instance is getting created...
You're not asking the right question, actually. The difference between put and createWithoutData is that they're completely different methods with totally unrelated purposes. In both cases you described, you're using the same put method. The difference is in how you're creating the ParseObject to put. In your first example, I believe when you write that to the database, it will insert the B row, then insert the A row with a pointer to the B. In the second example, you are using the ID from a Post row that is already in the database, and writing a pointer to that row into the Comment row.
Related
I was thinking if when i have to put something in an arrayMap i should use .put() or .setValueAt() , reading the documentation it seems to be the same thing,so what is the difference and when i sould prefer one or another?
The main difference is that .put() is used to insert a new item and can be used the first time you place an object in the arrayMap, .setValueAt() instead is used to update a value that is already inside the ArrayMap.
.put() can be even used to update a value but .setValueAt() can't be used to insert a new value the first time.
See the full documentation for all the infos:
https://developer.android.com/reference/android/support/v4/util/ArrayMap
i have some code like this:
ParseObject firstObject = ParseObject.create("oneClass");
//ParseObject secondObject = already exist on cloude - AnotherClass;
firstObject.put("pointer",secondObject);
firstObject.saveInBackground();
SecondClass beforeSave & afterSave triggered from some reason...
any idea?
When you save an object that has pointers attached to it, those pointers are also saved. This can be useful, or it can cause problems where your saves time out because you're calling extra beforeSave triggers. You just have to be aware of it and plan accordingly.
Also, FYI, when you query for objects that have fields that contain pointers, the pointers that are returned are empty pointers, i.e. they just contain the objectId. If you want to access them, use the include method of your query so that those objects are fetched as well.
I have a parseobject which consists of many objects, notably an array of consisting of ParseUser pointers.
When an individual clicks a button, the array should remove a certain User.
I don't get how to do this,
I have tried:
mRideEdit.removeAll("Participant", (Collection) childuser);
Where mRideEdit is my ParseClass, Participant is the array consisting of ParseUsers, and childuser is the user I want to remove
Please help,
I've recently faced the same problem.
It originates from how the ParseObjects (including ParseUser) are saved on the server.
If you look at the console, you'll see it is actually an array of strings created from the JSONObject toString method.
The simple answer is - You're using it wrong.
There is no sense in saving objects in such a way (though it's very intuitive).
As you probably noticed - you don't receive them as objects with the getJSONArray method either and have to get them from their objectIds.
The best way to do this is using relations.
If you're set on avoiding relations, what I'd suggest is saving them as strings from the get go (objectId). That way add, addUnique and removeAll will work just fine.
Hope this helps.
I'm new in programming for Android so maybe my question will be very easy to solve but still. I'm trying to make an array of different data types :
I have to add there :
int number
String name
int number_2
int time
int total
And my question now is how to implement it in easiest way, and how to get data from it. In case that I have to get a different records for this variables and store it into list .
Also have a question about way how to keep all values which I handle inside of my array.
I have to keep it because in my program I have to go back to other activities go forward to another and again collect data and add it to my array.
What will be the best and easiest solution ?
Thanks in advance for help
You could create the Array as an Array of Objects. All other classes are derived from Object, so you'll be able to store all types of objects in your Array. However, you would have to check the type of an object you get from the Array, before you'd be able to safely interpret as an object of a specific class. Moreover, you would have to use Integer instead of int.
If all (or at least multiple) of your elements you are intending to store in the Array are belonging to one (physical) entity, you could create a custom Class that holds its own properties as class members, and fill your Array with a list of instances of this Class.
Moreover, if you plan to add elements to your Array, you should use a List instead, e.g. an ArrayList.
As for retaining your data, you would have to either store it in a database, or save it to a file. In either way, you will have to save it upon close of the Activity, and load it again once the Activity starts
To pass the data across activities you will need to pass them using objects you can store in an intent. Seems like the best way to handle that is to either create a PREFS file to store the data or to create an object that extends Parcelable like here:
https://stackoverflow.com/questions/18593619/android-parcelable-object-passing-to-another-activity
Parcelables are preferable assuming you need all the data in a single object, you do not want to "putExtra" a bunch of fields and you also want to be sure data can pass from one activity to another. Otherwise, a simple Util class that reads and writes to a PREFS file is the way to go:
android read/write user preferences
A database is always another option, but seems well outside the scope of your question.
I'm making (my first) android application and I'm a little bit puzzled with the use of db4o.
I have one activity in which I have a listView, and let the user select an object. Then I pass this object trough a series of intents to other activities (to populate its fields) and then back to the main activity.
But the problem is, when I pass an object (it is serializable), the object I get out of the intent is not the same as the one I put in. (different id, when I check with debug).
All the fields are the same, but it's just not 'the same' object.
So when I try to store the updated object in the db4o, it doesn't recognize it, and stores a double.
I've figured out two workarounds:
Also pass an 'original/unmodified' object, and use it to get the db4o reference (through QBE), and then updating the fields of that object with the values of the changed object.
Using global variables so I don't have to use intents (to pass the object)
But both seem really bad to me? What could be a real solution, instead of a workaround?
You could try using a singleton to store your object and the fields that other classes (?) need to set so everyone has access. I'm not clear of your use of intents in this explanation.