Parse Local Datastore: I can't access ACL secured objects from the network after force closing the app? (Android)

StackOverflow https://stackoverflow.com/questions/23586362

Question

After a successful login I'm calling:

ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.isAuthenticated()

Now if I switch to another app via the home button or multitasking and return to my app the currentUser is still authenticated.

But if I force close the app and then reopen it the currentUser is not authenticated. Therefore it seems that I can't access any objects from the network which have the default Access Control List (ACL) added to them via:

Parse.enableLocalDatastore(this);
ParseACL.setDefaultACL(new ParseACL(), true);

Update with sample code:

    // Pinning
    ParseObject gameScore = new ParseObject("GameScore");
    gameScore.put("score", 1337);
    gameScore.put("playerName", "Sean Plott");
    gameScore.put("cheatMode", false);
    gameScore.pinInBackground("NEW_GAMESCORES", null);

    // Syncing Local Changes
    ParseQuery<ParseObject> localQueryNewScores = ParseQuery
            .getQuery("GameScore");
    localQueryNewScores.fromPin("NEW_GAMESCORES");

    localQueryNewScores.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> scores, ParseException e) {

            Log.d("score", "New scores = " + scores.size());

            for (ParseObject score : scores) {
                score.saveInBackground();
                score.unpinInBackground("NEW_GAMESCORES", null);

                score.pinInBackground("GAMESCORES", null);
            }
        }
    });

    // Syncing Network Changes
    ParseQuery<ParseObject> networkQueryScores = ParseQuery
            .getQuery("GameScore");

    // Query for new results from the network.
    networkQueryScores.findInBackground(new FindCallback<ParseObject>() {
        public void done(final List<ParseObject> scores, ParseException e) {

            Log.d("score", "Network scores = " + scores.size());

            // Remove the previously cached results.
            ParseObject.unpinAllInBackground("GAMESCORES",
                    new DeleteCallback() {
                        public void done(ParseException e) {
                            // Cache the new results.
                            ParseObject.pinAllInBackground("GAMESCORES",
                                    scores);
                        }
                    });
        }
    });

    // Querying the Local Datastore
    ParseQuery<ParseObject> localQueryScores = ParseQuery
            .getQuery("GameScore");
    localQueryScores.fromPin("GAMESCORES");

    localQueryScores.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> scores, ParseException e) {
            Log.d("score", "Local scores = " + scores.size());
        }
    });

Log output just after I've ran the code several times:

New scores = 2
Local scores = 0
Network scores = 0

New scores = 0
Local scores = 0
Network scores = 2

New scores = 2
Local scores = 2
Network scores = 2

New scores = 1
Local scores = 2
Network scores = 4

Log output just after I've force closed the app:

New scores = 0
Local scores = 4
Network scores = 0

New scores = 2
Local scores = 0
Network scores = 0

As you can see at Network scores = 0 after the force close I am unable to query any results from the network where I // Query for new results from the network to update the pinned objects in the Local Datastore with new results from the network. This happens even though I am constantly connected to the internet after the first login.

But as I need to sync back changes from the network to the Local Datastore I'm depending on this query.

So how can I still query the network for objects that are stored with ACL added to the currentUser, after I force close the app?

Update 2

I found others with the same problem which has been reported here: developers.facebook.com/bugs/702967266408226

It seems to be a bug in the new Parse Android SDK 1.5. I will update this post as soon as it's clear that my problem was related to the reported bug.

Was it helpful?

Solution 4

Parse Android Changelog

v1.5.1 — May 30, 2014

Fixed various bugs with Local Datastore.

The problem was indeed a Local Datastore bug which has been fixed today with the release of the new Parse Android SDK version 1.5.1.

OTHER TIPS

Maybe save password to file, and if u reopen app after force close, log in with this saved password ?

You could save the username and password in a SharedPreferences and log in again when the user re opens your app.

I think you could just check to see whether getCurrentUser is null or not instead of using isAuthenticated.

boolean isLoggedIn = ParseUser.getCurrentUser() != null;

isAuthenticated states:

Whether the ParseUser has been authenticated on this device. This will be true if the ParseUser was obtained via a logIn or signUp method. Only an authenticated ParseUser can be saved (with altered attributes) and deleted.

getCurrentUser is always the user that has signed up or logged in. So if it is not null, the user is logged in. isAuthenticated is just to see if the user object was retrieved from a login/sign up or not. For example, if you queried for other ParseUser objects, they would not be authenticated.

Also notice that when you do a logOut on the current user, getCurrentUser will be null.

I also noticed that if you were not using the Local Datastore, currentUser.isAuthenticated() would always return true even when force closing the application.

It seems that when you are using the Local Datastore, where the current user is retrieved locally, the object is no longer seen as "authenticated" as in the source is not from a login or sign up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top