Parse android download






















Nov 21, Oct 13, Oct 11, Mar 21, Apr 5, Oct 21, Update dependencies Dec 11, Update to support 26, gradle 4. Changes min to Aug 22, Oct 27, View code. Parse ; import android. Builder this. Each ParseObject has a class name that you can use to distinguish different sorts of data. For example, we could call the high score object a GameScore.

The interface is similar to a Map , plus the saveInBackground method:. After this code runs, you will probably be wondering if anything really happened. To make sure the data was saved, you can look at the Data Browser in your app on Parse. You should see something like this:.

There are two things to note here. Your Parse app lazily creates this Class for you when it first encounters it. If you have the objectId , which is available once the ParseObject been uploaded to the server, you can retrieve the whole ParseObject using a ParseQuery :.

In most situations you should use the typed accessors like getString. If you need to refresh an object you already have with the latest data that is in the cloud, you can call the fetchInBackground method like so:. The code in the GetCallback will be run on the main thread.

Parse also lets you store objects in a local datastore on the Android device itself. To enable the datastore, call Parse. Once the local datastore is enabled, you can store an object by pinning it. As with saving, this recursively stores every object and file that gameScore points to, if it has been fetched from the cloud. Storing an object is only useful if you can get it back out. To get the data for a specific object, you can use a ParseQuery just like you would while on the network, but using the fromLocalDatastore method to tell it where to get the data.

If you already have an instance of the object, you can instead use the fetchFromLocalDatastoreInBackground method. When you are done with the object and no longer need to keep it on the device, you can release it with unpinInBackground.

Most save functions execute immediately, and inform your app when the save is complete. If your app is closed before the connection is back, Parse will try again the next time the app is opened. All calls to saveEventually and deleteEventually are executed in the order they are called, so it is safe to call saveEventually on an object multiple times.

If you have the local datastore enabled, then any object you saveEventually will be pinned as long as that save is in progress. That makes it easy to retrieve your local changes while waiting for the network to be available. Updating an object is simple. Just set some new data on it and call one of the save methods. Assuming you have saved the object and have the objectId , you can retrieve the ParseObject using a ParseQuery and update its data:.

The above example contains a common use case. To help with storing counter-type data, Parse provides methods that atomically increment or decrement any number field.

So, the same update can be rewritten as:. You can also increment by any amount using increment key, amount. To help with storing array data, there are three operations that can be used to atomically change an array field:. Note that it is not currently possible to atomically add and remove items from an array in the same save. You will have to call save in between every different kind of array operation.

If you want to run a callback when the delete is confirmed, you can provide a DeleteCallback to the deleteInBackground method. If you want to block the calling thread, you can use the delete method. You can delete a single field from an object with the remove method:. Objects can have relationships with other objects. To model this behavior, any ParseObject can be used as a value in other ParseObject s.

Internally, the Parse framework will store the referred-to object in just one place, to maintain consistency. For example, each Comment in a blogging app might correspond to one Post. To create a new Post with a single Comment , you could write:.

You can also link objects using just their objectId s like so:. By default, when fetching an object, related ParseObject s are not fetched. You can also model a many-to-many relation using the ParseRelation object.

For example, a User may have many Post s that they might like. In this case, you can store the set of Post s that a User likes using getRelation. In order to add a post to the list, the code would look something like:. You can remove a post from the ParseRelation with something like:. By default, the list of objects in this relation are not downloaded. The code would look like:.

If you want only a subset of the Post s you can add extra constraints to the ParseQuery returned by getQuery. The code would look something like:. For more details on ParseQuery , please look at the query portion of this guide. Parse also supports float , java.

Overall, the following types are allowed for each field in your object:. We do not recommend storing large pieces of binary data like images or documents on ParseObject. We recommend you use ParseFile s to store images, documents, and other types of files.

You can do so by instantiating a ParseFile object and setting it on a field. See Files for more details. For more information about how Parse handles data, check out our documentation on Data. Parse is designed to get you up and running as quickly as possible. You can access all of your data using the ParseObject class and access any field with get. In mature codebases, subclasses have many advantages, including terseness, extensibility, and support for autocomplete.

Subclassing is completely optional, but can transform this code:. Adding methods to your ParseObject subclass helps encapsulate logic about the class.

You can add accessors and mutators for the fields of your ParseObject easily. Declare the getter and setter for the field as you normally would, but implement them in terms of get and put.

The following example creates a displayName field in the Armor class:. You can now access the displayName field using armor. This allows your IDE to provide autocompletion as you develop your app and allows typos to be caught at compile-time. Accessors and mutators of various types can be easily defined in this manner using the various forms of get such as getInt , getParseFile , or getMap.

If you need more complicated logic than simple field access, you can declare your own methods as well:. You should create new instances of your subclasses using the constructors you have defined.

Your subclass must define a public default constructor that does not modify fields of the ParseObject , which will be used throughout the Parse SDK to create strongly-typed instances of your subclass. To create a reference to an existing object, use ParseObject. You can get a query for objects of a particular subclass using the static method ParseQuery. The following example queries for armors that the user can afford:. This means you can retain a ParseObject during configuration changes, or pass objects to other components through Bundle s.

To achieve this, depending on the context, use either Parcel writeParcelable Parcelable, int or Bundle putParcelable String, Parcelable. For instance, in an Activity ,. ParseObject will parcel its internal state, along with unsaved children and dirty changes. There are, however, a few things to be aware of when parceling objects that have ongoing operations, like save or delete.

When the Local Datastore is enabled, parceling a ParseObject is a safe operation even if there are ongoing save or delete operations. The unparceled object, being a different instance than the source object,.

The unfortunate consequence is that keys that were dirty before saving will still be marked as dirty for the unparceled object. This means, for instance, that any future call to saveInBackground will send these dirty operations to the server again.

This can lead to inconsistencies for operations like increment , since it might be performed twice. By default, ParseObject implementation parcels everything that is needed. If your subclasses have stateful information that you would like to keep when parceling, you can simply override onSaveInstanceState Bundle and onRestoreInstanceState Bundle :.

There are many other ways to retrieve data with ParseQuery - you can retrieve many objects at once, put conditions on the objects you wish to retrieve, cache queries automatically to avoid writing that code yourself, and more. The ParseQuery offers different ways to retrieve a list of objects rather than just a single object.

The general pattern is to create a ParseQuery , put conditions on it, and then retrieve a List of matching ParseObject s using the findInBackground method with a FindCallback. For example, to retrieve scores with a particular playerName , use the whereEqualTo method to constrain the value for a key:.

There are several ways to put constraints on the objects found by a ParseQuery. You can filter out objects with a particular key-value pair with whereNotEqualTo :.

You can give multiple constraints, and objects will only be in the results if they match all of the constraints. You can limit the number of results with setLimit. By default, results are limited to In the old Parse hosted backend, the maximum limit was 1,, but Parse Server removed that constraint:. If you want exactly one result, a more convenient alternative may be to use getFirst or getFirstInBackground instead of using find.

You can skip the first results with setSkip. In the old Parse hosted backend, the maximum skip value was 10,, but Parse Server removed that constraint. This can be useful for pagination:. For sortable types like numbers and strings, you can control the order in which results are returned:. If you want to retrieve objects matching several different values, you can use whereContainedIn , providing a collection of acceptable values. This is often useful to replace multiple queries with a single query.

For example, if you want to retrieve scores made by any player in a particular list:. If you want to retrieve objects that do not match any of several values you can use whereNotContainedIn , providing an array of acceptable values. For example, if you want to retrieve scores from players besides those in a list:. If you want to retrieve objects that have a particular key set, you can use whereExists. Conversely, if you want to retrieve objects without a particular key set, you can use whereDoesNotExist.

You can use the whereMatchesKeyInQuery method to get objects where a key matches the value of a key in a set of objects resulting from another query. The query would look like:. Conversely, to get objects where a key does not match the value of a key in a set of objects resulting from another query, use whereDoesNotMatchKeyInQuery.

For example, to find users whose hometown teams have losing records:. You can restrict the fields returned by calling selectKeys with a collection of keys. To retrieve documents that contain only the score and playerName fields and also special built-in fields such as objectId , createdAt , and updatedAt :.

The remaining fields can be fetched later by calling one of the fetchIfNeeded variants on the returned objects:. Use whereStartsWith to restrict to string values that start with a particular string. Queries that have regular expression constraints are very expensive.

Refer to the Performance Guide for more details. You can use whereFullText for efficient search capabilities. Text indexes are automatically created for you.

Your strings are turned into tokens for fast searching. Note: Full Text Search can be resource intensive. There are several ways to issue queries for relational data.

If you want to retrieve objects where a field matches a particular ParseObject , you can use whereEqualTo just like for other data types. For example, if each Comment has a Post object in its post field, you can fetch comments for a particular Post :. If you want to retrieve objects where a field contains a ParseObject that matches a different query, you can use whereMatchesQuery. In order to find comments for posts containing images, you can do:. If you want to retrieve objects where a field contains a ParseObject that does not match a different query, you can use whereDoesNotMatchQuery.

In order to find comments for posts without images, you can do:. In some situations, you want to return multiple types of related objects in one query. You can do this with the include method.

You can also do multi level includes using dot notation. You can issue a query with multiple fields included by calling include multiple times. If you have enabled the local datastore by calling Parse. To do this, call the fromLocalDatastore method on the query. You can query from the local datastore using exactly the same kinds of queries you use over the network. For example, if you call deleteEventually , on an object, it will no longer be returned from these queries. The easiest way to do this is with the local datastore.

When you pin objects, you can attach a label to the pin, which lets you manage a group of objects together. For example, to cache the results of the query above, you can call pinAllInBackground and give it a label. Now when you do any query with fromLocalDatastore , these objects will be included in the results if they still match the query.

ParseQuery lets you choose whether to query the network fromNetwork or the local datastore fromLocalDatastore or fromPin label to query just a subset. It is also possible to chain both requests, or execute them in parallel.

For example, to try the network and then fall back to cached data if the network is not available:. You can do the following operations on the cache:.

Note: In the old Parse hosted backend, count queries were rate limited to a maximum of requests per minute. They also returned inaccurate results for classes with more than 1, objects. But, Parse Server has removed both constraints and can count objects well above 1, If you just need to count how many objects match a query, but you do not need to retrieve all the objects that match, you can use count instead of find.

For example, to count how many games have been played by a particular player:. If you want to block the calling thread, you can also use the synchronous query. If you want to find objects that match one of several queries, you can use ParseQuery. For instance if you want to find players who either have a lot of wins or a few wins, you can do:.

Note that we do not, however, support GeoPoint or non-filtering constraints e. At the core of many apps, there is a notion of user accounts that lets users access their information in a secure manner.

We provide a specialized user class called ParseUser that automatically handles much of the functionality required for user account management. ParseUser is a subclass of the ParseObject , and has all the same features, such as flexible schema, automatic persistence, and a key value interface. All the methods that are on ParseObject also exist in ParseUser. The difference is that ParseUser has some special additions specific to user accounts. ParseUser has several properties that set it apart from ParseObject :.

Keep in mind that if you set username and email using the setters, you do not need to set it using the put method. The first thing your app will do is probably ask the user to sign up.

The following code illustrates a typical sign up:. This call will asynchronously create a new user in your Parse App. Before it does this, it checks to make sure that both the username and email are unique.

Also, it securely hashes the password in the cloud using bcrypt. We never store passwords in plaintext, nor will we ever transmit passwords back to the client in plaintext. Subsequent updates to a user can be done by calling save. The signUpInBackground method comes in various flavors, with the ability to pass back errors, and also synchronous versions.

As usual, we highly recommend using the asynchronous versions when possible, so as not to block the UI in your app. You can read more about these specific methods in our API docs. The most likely case is that the username or email has already been taken by another user.

You should clearly communicate this to your users, and ask them try a different username. You are free to use an email address as the username. Simply ask your users to enter their email, but fill it in the username property — ParseUser will work as normal.

Of course, after you allow users to sign up, you need be able to let them log in to their account in the future.

To do this, you can use the class method logInInBackground. Email verification adds the emailVerified key to the ParseUser object. Parse then emails the user a link which will set emailVerified to true. There are three emailVerified states to consider:. It would be bothersome if the user had to log in every time they open your app. You can avoid this by using the cached currentUser object. Whenever you use any signup or login methods, the user is cached on disk.

You can treat this cache as a session, and automatically assume the user is logged in:. Being able to associate data and objects with individual users is highly valuable, but sometimes you want to be able to do this without forcing a user to specify a username and password.

An anonymous user is a user that can be created without a username and password but still has all of the same capabilities as any other ParseUser. After logging out, an anonymous user is abandoned, and its data is no longer accessible. You can create an anonymous user using ParseAnonymousUtils :. You can convert an anonymous user into a regular user by setting the username and password, then calling signUp , or by logging in or linking with a service like Facebook or Twitter.

The converted user will retain all of its data. To determine whether the current user is an anonymous user, you can check ParseAnonymousUtils. Anonymous users can also be automatically created for you without requiring a network request, so that you can begin working with your user immediately when your application starts. When you enable automatic anonymous user creation at application startup, ParseUser. The user will automatically be created in the cloud the first time the user or any object with a relation to the user is saved.

Enabling automatic user creation makes associating data with your users painless. For example, in your Application. This method will ensure the session token is valid before setting the current user. The ParseUser class is secured by default. Data stored in a ParseUser can only be modified by that user. By default, the data can still be read by any client. Thus, some ParseUser objects are authenticated and can be modified, whereas others are read-only.

Specifically, you are not able to invoke any of the save or delete type methods unless the ParseUser was obtained using an authenticated method, like logIn or signUp.

This ensures that only the user can alter their own data. The ParseUser obtained from getCurrentUser will always be authenticated. If you need to check if a ParseUser is authenticated, you can invoke the isAuthenticated method. You do not need to check isAuthenticated with ParseUser objects that are obtained via an authenticated method.

The same security model that applies to the ParseUser can be applied to other objects. For any object, you can specify which users are allowed to read the object, and which users are allowed to modify an object. To support this type of security, each object has an access control list , implemented by the ParseACL class. The simplest way to use a ParseACL is to specify that an object may only be read or written by a single user.

To create such an object, there must first be a logged in ParseUser. Thus, to create a private note that can only be accessed by the current user:. This note will then only be accessible to the current user, although it will be accessible to any device where that user is signed in. This functionality is useful for applications where you want to enable access to user data across multiple devices, like a personal todo list. Permissions can also be granted on a per-user basis. This allows patterns like posting comments on a message board.

For example, to create a post that can only be edited by its author, but can be read by anyone:. In the code above, the second parameter to setDefaultACL tells Parse to ensure that the default ACL assigned at the time of object creation allows read and write access to the current user at that time.

Without this setting, you would need to reset the defaultACL every time a user logs in or out so that the current user would be granted access appropriately. With this setting, you can ignore changes to the current user until you explicitly need to grant different kinds of access.

Default ACLs make it easy to create apps that follow common access patterns. An application like Twitter, for example, where user content is generally visible to the world, might set a default ACL such as:. Operations that are forbidden, such as deleting an object that you do not have write access to, result in a ParseException. For security purposes, this prevents clients from distinguishing which object ids exist but are secured, versus which object ids do not exist at all.

In such cases, our library provides a way to let them securely reset their password. By doing this, you can opt to have users use their email as their username, or you can collect it separately and store it in the email field. Note that the messaging in this flow will reference your app by the name that you specified when you created this app on Parse. In addition, you can use get to get a ParseUser by id. Associations involving a ParseUser work right of the box.

To store a new post for a user and retrieve all their posts:. Parse provides an easy way to integrate Facebook with your application. Using our Facebook integration, you can associate an authenticated Facebook user with a ParseUser. These instructions are for Facebook SDK 4. This allows users of apps that support Facebook login to sign in directly through the Facebook app, using credentials that are already on the device. If the Facebook app is not installed, the default dialog-based authentication will be used.

If your Activity is already using onActivityResult , you can avoid requestCode collisions by specifying your own request code offset when initializing ParseFacebookUtils. Otherwise, a sensible default activityCode will be used. There are two main ways to use Facebook with your Parse users: 1 logging in as a Facebook user and creating a ParseUser , or 2 linking Facebook to an existing ParseUser.

In order to display the Facebook login dialogs and activities, the current Activity must be provided often, the current activity is this when calling logInWithReadPermissionsInBackground from within the Activity as we have done above. When logging in, you can only use read permissions.

See our documentation below about requesting additional permissions read or publish. If you want to associate an existing ParseUser to a Facebook account, you can link it like so:. The steps that happen when linking are very similar to log in.

The difference is that on successful login, the existing ParseUser is updated with the Facebook information. Future logins via Facebook will now log the user into their existing account.

As of v3. To request additional permissions, you may call ParseFacebookUtils. After successfully retrieving new permissions, please call ParseFacebookUtilities. Generally, you will use the GraphRequest class to interact with Facebook on behalf of your logged-in user. You can read more about the Facebook SDK here. As with Facebook, Parse also provides an easy way to integrate Twitter authentication into your application. If you encounter any issues that are Twitter-related, a good resource is the official Twitter documentation.

There are two main ways to use Twitter with your Parse users: 1 logging in as a Twitter user and creating a ParseUser , or 2 linking Twitter to an existing ParseUser. This is accomplished using the logIn method:. In order to display the Twitter login dialogs and activities, the current Context must be provided often, the current context is this when calling logIn from within the Activity as we have done above. If you want to associate an existing ParseUser with a Twitter account, you can link it like so:.

The difference is that on successful login, the existing ParseUser is updated with the Twitter information. Future logins via Twitter will now log the user into their existing account. Sessions represent an instance of a user logged into a device.

Sessions are automatically created when users log in or sign up. They are automatically deleted when users log out. We provide a set of APIs to manage Session objects in your app. Session is a subclass of a Parse Object , so you can query, update, and delete sessions in the same way that you manipulate normal objects on Parse.

Arduino or Embedded C. Unlike other Parse objects, the Session class does not have Cloud Code triggers. So you cannot register a beforeSave or afterSave handler for the Session class. The Session object has these special fields:. With revocable sessions, your current session token could become invalid if its corresponding Session object is deleted from your Parse Server. Sessions could also be deleted due to automatic expiration if configured in app settings.

To handle this error, we recommend writing a global utility function that is called by all of your Parse request error callbacks. You should prompt the user to login again so that they can obtain a new session token. This code could look like this:. Session objects can only be accessed by the user specified in the user field. All Session objects have an ACL that is read and write by that user only. You cannot change this ACL. This means querying for sessions will only return objects that match the current logged-in user.

When you log in a user via a User login method, Parse will automatically create a new unrestricted Session object in your Parse Server.

We recommend that you disable all CLPs not needed by your app. Here are some common use cases for Session CLPs:. As your app grows in scope and user-base, you may find yourself needing more coarse-grained control over access to pieces of your data than user-linked ACLs can provide. To address this requirement, Parse supports a form of Role-based Access Control. Roles provide a logical way of grouping users with common access privileges to your Parse data.

Roles are named objects that contain users and other roles. Any permission granted to a role is implicitly granted to its users as well as to the users of any roles that it contains.

By adding users to these roles, you can ensure that new users can be made moderators or administrators, without having to manually grant permission to every resource for each user. We provide a specialized class called ParseRole that represents these role objects in your client code.

ParseRole is a subclass of ParseObject , and has all of the same features, such as a flexible schema, automatic persistence, and a key value interface. All the methods that are on ParseObject also exist on ParseRole. The difference is that ParseRole has some additions specific to management of roles.

ParseRole has several properties that set it apart from ParseObject :. Generally, only users with greatly elevated privileges e.

Remember, if you give write-access to a ParseRole to a user, that user can add other users to the role, or even delete the role altogether. To create a new ParseRole , you would write:. Take great care when assigning ACLs to your roles so that they can only be modified by those who should have permissions to modify them. Now that you have created a set of roles for use in your application, you can use them with ACLs to define the privileges that their users will receive.

Each ParseObject can specify a ParseACL , which provides an access control list that indicates which users and roles should be granted read or write access to the object. Giving a role read or write permission to an object is straightforward. You can either use the ParseRole :. For example, a moderated forum application might specify a default ACL like this:.

As described above, one role can contain another, establishing a parent-child relationship between the two roles. The consequence of this relationship is that any permission granted to the parent role is implicitly granted to all of its child roles. These types of relationships are commonly found in applications with user-managed content, such as forums. Any user with Administrator privileges should also be granted the permissions of any Moderator.

ParseFile lets you store application files in the cloud that would otherwise be too large or cumbersome to fit into a regular ParseObject. The most common use case is storing images but you can also use it for documents, videos, music, and any other binary data. Getting started with ParseFile is easy. Notice in this example that we give the file a name of resume. As with ParseObject , there are many variants of the save method you can use depending on what sort of callback and error handling suits you.

Finally, after the save completes, you can associate a ParseFile onto a ParseObject just like any other piece of data:. Retrieving it back involves calling one of the getData variants on the ParseObject. Here we retrieve the resume file off another JobApplication object:. Just like on ParseObject , you will most likely want to use the background version of getData.

For example:. You will need to provide the master key in order to be allowed to delete a file. Keep in mind that doing so may break functionality which depended on accessing unreferenced files through their URL property. Files that are currently associated with an object will not be affected.

This means you can retain a ParseFile during configuration changes, or pass it to other components of the app through Bundles. For instance, in an Activity,. If you try to do so, an exception will be thrown. If you are not sure if your file has been saved, please check for! Parse allows you to associate real-world latitude and longitude coordinates with an object.

Adding a ParseGeoPoint to a ParseObject allows queries to take into account the proximity of an object to a reference point. This allows you to easily do things like find out what user is closest to another user or which places are closest to a user.

To associate a point with an object you first need to create a ParseGeoPoint. For example, to create a point with latitude of To retrieve a ParseGeoPoint from an object. Parse allows you to associate polygon coordinates with an object. To retrieve a ParsePolygon from an object.

We put our code to onCreate method because we want to connect to our server first before taking any other action. For doing this, go to the AndroidManifest. Find your app and go to its Dashboard. You should see the First Class with an object, as shown in the image below. Learn more by walking around our Android Tutorials. Prerequisites To complete this section, you will need: An app created at Back4App. Android Studio. Basic android app. Step 1 - Install SDK We need to implement Parse SDK to our Android project for this we will use Gradle , an open-source build automation tool that is designed to be flexible enough to build almost any type of software.

Parse ;.



0コメント

  • 1000 / 1000