7

It's simple, when you use parse for the first time on your mobile it works like a charm. When you reinstall your application, it screws everything.

As stated on stackoverflow by Eran:

"PushService.subscribe seems to cache the subscription in local storage, to avoid re-subscribing when you launch the app multiple times. This is what the first parameter of that method is used for : context - This is used to access local storage to cache the subscription, so it must currently be a viable context. (quote from here).

However, when you uninstall the app, local storage for that app is wiped from your device, so the new installation will cause PushService.subscribe to re-register to Google Cloud Messaging. If the new registration returns a new registration ID, Parse would have two registration IDs that can be used to send push notifications to your app, and both of them would be linked to the same userName you supplied to subscribe. Therefore sending a notification to that userName will send it to both registration IDs, causing it to arrive twice.

When Parse send the notifications for you, they should get from Google a response with canonical_registration_id, which will let them know one of the registration IDs associated with your app on your device is old, and should not be used anymore. Therefore (assuming Parse have a decent implementation of GCM) the next time you send a notification to your device, you should receive it only once."

Here is my source code for the installation:

String  androidId = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
Parse.initialize(this, "KEY1", "KEY2");
PushService.setDefaultPushCallback(this, ParseActivity.class);

ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("UniqueId",androidId);

installation.setObjectId(null);

installation.saveInBackground();

My stacktrace (like everyones):

05-20 19:47:35.630: E/ParseCommandCache(6497): com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseCommand.onPostExecute(ParseCommand.java:334)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseRequest$5.then(ParseRequest.java:321)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseRequest$5.then(ParseRequest.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:481)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWithTask(Task.java:353)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWithTask(Task.java:364)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$9.then(Task.java:410)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$9.then(Task.java:402)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:481)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$400(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:346)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:343)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$300(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:311)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:308)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$300(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:311)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:308)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:329)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$400(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:346)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:343)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:329)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at java.lang.Thread.run(Thread.java:841)
05-20 19:48:32.615: D/Request(6497): Warning: Sessionless Request needs token but missing either application ID or client token.

Since I've not found any real solution, I'm asking here.

Thanks.

Community
  • 1
  • 1
Maurício Giordano
  • 3,116
  • 4
  • 32
  • 60
  • Have you found a solution? – Chad Bingham May 25 '14 at 21:30
  • @Binghammer are you with the same problem? I still don't have a solution... Already asked on `Parse` forum and also placed a new Bug in Facebook Developers. – Maurício Giordano May 25 '14 at 22:26
  • 1
    Yes, I have the same problem. Check my question, maybe it could help you? http://stackoverflow.com/questions/23860586/facebook-parse-login-behaving-strange – Chad Bingham May 25 '14 at 22:34
  • 1
    I've the same issue. It really makes no sense, I register my ParseInstallation exactly like you. So the uniqueId is always stored, but the deviceToken appear and disappear randomly. The push notification is retrieved only if there is a deviceToken, as I see.. This is a big trouble! It seems that Parse's gcm implementation is very poor. – Marino Aug 19 '14 at 02:53

4 Answers4

0

I'm definitely convinced that this is caused by a parse bug. Same thing is said by a lot of unresolved bug reports I found at Parse.com. I'm currently working with Parse 1.5.1: The thing that I've seen is that without deviceToken the push aren't sent, and without the uniqueId we get the runtime error here above. If I send the UniqueId immediately after the registration, a row without deviceToken is saved. The solution for me, tested on Nexus 5, Nexus 4 and Sony xperia E: In your Application class onCreate()

    Parse.initialize(this, PARSE_APP_KEY_VALUE, PARSE_CLIENT_KEY_VALUE);
    PushService.setDefaultPushCallback(getApplicationContext(), MainActivity.class);
    final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    final String  androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
        // Post the uniqueId delayed
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    installation.put("UniqueId", androidId);
                                    installation.saveInBackground(new SaveCallback() {
                                        @Override
                                        public void done(ParseException e) {
                                            // Saved!
                                        }
                                    });
                                }
                            }, 10000
        );

Working this way, I'm able to save correct rows (with uniqueId and deviceToken), and to send push notification! Cheers!

Marino
  • 800
  • 1
  • 12
  • 26
  • Thanks! But I've solved my problem by creating a server and implementing the server side of GCM and APN myself (there are great libraries on NPM for Node.JS). Thanks anyway! – Maurício Giordano Sep 02 '14 at 19:50
0

I was also facing this issue. I sort of solved it by calling the below method in my Activity's onCreate()

/**
     * Initialize Push Messaging Service and subscribe to all-users channel
     */
    private void initParsePushMessaging() {
        ParseInstallation parseInstallation = ParseInstallation
                .getCurrentInstallation();
        //You might skip this if
        if (ParseUser.getCurrentUser() != null) {
            parseInstallation.put("user",
                    ParseUser.getCurrentUser());
        }
        if (parseInstallation.getObjectId() != null)
            parseInstallation.saveInBackground(new SaveCallback() {

                @Override
                public void done(ParseException e) {
                    PushService.subscribe(getApplicationContext(),"channel_name",
                            MainHomeActivity.class);
                }
            });

    }

Even though it didn't completely solve my problem but now my app doesn't hang and no more ANR's due to this Parse implementation. If i re install an app and run it now then the app creates a new installation record and remove's the last one. The only problem is that the channel_name is not subscribed on this run but on the next run the channel are successfully subscribed.

Sheraz Ahmad Khilji
  • 8,300
  • 9
  • 52
  • 84
  • Hi Sheraz, can you add more on : 1) What is ANR? 2) How does this code remove the previous installation record? – Jo Dar Gaya Woh Mar Gaya Dec 27 '14 at 12:30
  • @GabbarSingh ANR is application Not Responding dialog. This usually happens if you do any operation on UI thread that takes more than 3 seconds [blocks UI thread for more than 3 seconds]. And as for Removing previous installation record, Parse does that automatically by overwriting your old installation record with the new record. – Sheraz Ahmad Khilji Dec 29 '14 at 07:52
  • Thanks, from forums I gather that Parse is able to maintain one install record for iphone apps, but creates multiple install records for Android apps (eg. when user updates an app, old installation record persists and new one is created for updated version of app). This is a problem when sending push notifications a s you get charged for messages per installed app basis (and some of those install ids are are obsolete). Can you confirm if you have seen that problem. I am in process of evaluating Parse's limitation, and check if it is worth working around them or writing a backend myself. Thanks – Jo Dar Gaya Woh Mar Gaya Dec 29 '14 at 15:17
0

What worked for me to get rid of this exception was using saveEventually() instead of saveInBackground().

Here you have a link to my answer to a similar question.

I think that saveEventually() is a better option because it assures that the installation will always be saved, regardless of the netwwork availability. In contrast, with saveInBackground() there is a chance that the save fails due to no network connectivity. Also with saveEventually() you don't need to do any error checking, which you should do in a SaveCallback() with saveInBackground().

Community
  • 1
  • 1
Albert Vila Calvo
  • 15,298
  • 6
  • 62
  • 73
0

Had the exact same problem. I solved it by going to settings on my phone -> Apps -> your application name -> Force shutdown -> Uninstall.

Then in Android studio I went -> File -> Invalidate Caches / Restart -> Wait for the gradle to build again and then run the Application on my phone. Worked like a charm.

Danieboy
  • 4,393
  • 6
  • 32
  • 57