androidparse-platformparse-serverparse-android-sdk

ParseInstallation.getCurrentInstallation().getObjectId() returns null in the particular user's smartphone


I have my Android app using the Parse server for backend service. A number of users are currently using my Android app. However, some particular users faced the problem at app installation that an object is not created in the Installation table even after log-in.

When I took a look at the problem from my Android app with some Analytics code, I found that ParseInstallation.getCurrentInstallation().getObjectId() returns null for the user even though Parse initialization process is completed properly. With the Analytics code, I checked the method every 10 seconds for 10 minutes after Parse initialization, but that method always returned null for the particular user.

// Parse initialization in the onCreate() of Application class
Parse.enableLocalDatastore(this);
Parse.initialize(new Parse.Configuration.Builder(this)
        .applicationId(getString(R.string.parse_app_id))
        .clientKey(getString(R.string.parse_client_key))
        .server(getString(R.string.parse_server_api))
        .build());
ParseUser.enableAutomaticUser();
ParseACL.setDefaultACL(new ParseACL(), true);

// After Log-In, Save the installation.
// (My app user normally would come here 20 ~ 30 seconds or long after the above Parse initialization.) 
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
if (!TextUtils.isEmpty(installation.getObjectId()) { // installation.getObjectId() returns null for the particular user.
    installation.put("GCMSenderId", getString(R.string.fcm_sender_id));
    installation.saveInBackground(
        // will associate the Installation with the User in new SaveCallback()
    );
}

// build.gradle(Module: app)
implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.18.5' 
implementation 'com.github.parse-community.Parse-SDK-Android:fcm:1.18.5'

Most users get valid ObjectId and work correctly without any problem. However, once a user encounters the problem, the object is no longer created in the Installation table for the user, even though the user installs the app again.

I do not know if this is a fundamental problem with the Parse server.

Any advice will be helpful to me.


Solution

  • I think that the objectId is null because the installation is not saved for some reason. I'd recommend you to go with the following code and check again:

    // Parse initialization in the onCreate() of Application class
    Parse.enableLocalDatastore(this);
    Parse.initialize(new Parse.Configuration.Builder(this)
            .applicationId(getString(R.string.parse_app_id))
            .clientKey(getString(R.string.parse_client_key))
            .server(getString(R.string.parse_server_api))
            .build());
    ParseUser.enableAutomaticUser();
    ParseACL.setDefaultACL(new ParseACL(), true);
    
    // After Log-In, Save the installation.
    // (My app user normally would come here 20 ~ 30 seconds or long after the above Parse initialization.) 
    ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    if (TextUtils.isEmpty(installation.getObjectId())) { // installation.getObjectId() returns null for the particular user.
        installation.save();
    }
    installation.put("GCMSenderId", getString(R.string.fcm_sender_id));
    installation.saveInBackground(
        // will associate the Installation with the User in new SaveCallback()
    );
    
    // build.gradle(Module: app)
    implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.18.5' 
    implementation 'com.github.parse-community.Parse-SDK-Android:fcm:1.18.5'