Parse Android SDK

repository·master·Indexed 23 days ago

https://github.com/parse-community/parse-sdk-android

A client-side interface for Android applications to interact with a Parse Server backend, providing features for data storage, user authentication, and push notifications. Version 4.4.0 includes optional modules for Kotlin Coroutines, KTX property delegation, FCM push support, and social authentication via Google and Facebook.

Tokens
6.1K
Snippets
27
Records
33
Agent score
83%

What's inside Parse Android SDK

  1. Explore related Parse Android libraries

    master

    The Parse community provides several specialized libraries to extend functionality:

    • ParseGoogleUtils: Google login/signup.
    • ParseFacebookUtils: Facebook login/signup.
    • ParseTwitterUtils: Twitter login/signup.
    • Parse FCM: Firebase Cloud Messaging support for push notifications.
    • Parse KTX: Kotlin extensions for ease of use.
    • Parse Coroutines: Kotlin Coroutines support for async operations.
    • Parse RxJava: Transform Parse Tasks to RxJava Completables and Singles.
    • ParseLiveQuery: Realtime query subscription.
    • ParseUI: Prebuilt UI elements.
  2. Use property delegation for ParseObject attributes

    master

    The KTX module provides property delegates to eliminate the boilerplate of writing manual get() and set() methods for ParseObject attributes. Instead of manually calling getString(), put(), or getInt(), you can use delegates like stringAttribute() and intAttribute() directly on your class properties.

    @ParseClassName("Cat")
    class Cat : ParseObject() {
    
        var name: String by stringAttribute() // That's it
        var legs: Int by intAttribute("cat-legs")
    
    }
  3. Initialize Parse Android SDK

    master

    To initialize the SDK, call Parse.initialize() within the onCreate() method of a custom class that extends android.app.Application. You must provide an applicationId and optionally a clientKey and server URL via the Parse.Configuration.Builder.

    Important: You must register your custom Application class in your AndroidManifest.xml using the android:name attribute.

    Note on HTTP: If testing with an http server (instead of https), you must add android:usesCleartextTraffic="true" to your <application> tag in AndroidManifest.xml. Use https for production.

    import com.parse.Parse;
    import android.app.Application;
    
    public class App extends Application {
        @Override
        public void onCreate() {
          super.onCreate();
    
          Parse.initialize(new Parse.Configuration.Builder(this)
            .applicationId("YOUR_APP_ID")
            // if desired
            .clientKey("YOUR_CLIENT_KEY")
            .server("https://your-server-address/parse/")
            .build()
          );
        }
    }
    <application
        android:name=".App"
        ...>
        ...
    </application>
  4. Convert Parse Tasks to RxJava types in Kotlin

    master

    RxJava support is provided as extension methods on any Task. You can convert a Task<T> into a Single<T> or a Task<Void> into a Completable.

    // Converting a Task<ParseUser> to a Single
    ParseTwitterUtils.logInInBackground(this)
        .toSingle()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            Timber.d("Logged in with user ${it.objectId}")
        }, {
            Timber.e(it)
        })
    
    // Converting a Task<Void> to a Completable
    val user = ParseUser.getCurrentUser()
    user.put("lastLoggedIn", System.currentTimeMillis())
    user.saveInBackground().toCompletable()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            Timber.d("user saved")
        }, {
            Timber.e(it)
        })
  5. Handle Facebook login activity results

    master

    In the Activity where the user performs the login, you must override onActivityResult and pass the result to ParseFacebookUtils.onActivityResult to ensure the Facebook SDK processes the login response correctly.

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
    }
  6. Add Parse SDK Android KTX dependency

    master

    To use Kotlin extension functions and property delegation for ParseObject subclasses, add the KTX module to your Gradle dependencies. Ensure you have JitPack configured in your project first.

    dependencies {
        implementation "com.github.parse-community.Parse-SDK-Android:ktx:latest.version.here"
    }
  7. Install Parse Android SDK and optional modules

    master

    Add the Parse SDK to your module-level build.gradle file. You can also include optional modules for social login (Google, Facebook, Twitter), FCM Push support, Kotlin extensions (KTX), Coroutines, or RxJava support.

    Replace latest.version.here with the specific version you wish to use.

    ext {
       parseVersion = "latest.version.here"
    }
    dependencies {
        implementation "com.github.parse-community.Parse-SDK-Android:parse:$parseVersion"
        // for Google login/signup support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:google:$parseVersion"
        // for Facebook login/signup support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:facebook:$parseVersion"
        // for Twitter login/signup support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:twitter:$parseVersion"
        // for FCM Push support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:fcm:$parseVersion"
        // for Kotlin extensions support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:ktx:$parseVersion"
        // for Kotlin coroutines support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:coroutines:$parseVersion"
        // for RxJava support (optional)
        implementation "com.github.parse-community.Parse-SDK-Android:rxjava:$parseVersion"
    }