Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Implementing Designs for Android Adding Push Notifications from Parse.com Preparing User-to-User Push Notifications

Really need help on preparing user-to-user push notification code challenge task 2.

I have been working on this for an hour and could really use some help please tell me whats wrong with my code.

LoginActivity.java
import android.app.Activity;
import android.os.Bundle;
import com.parse.ParseInstallation;
import com.parse.ParseUser;

public class LoginActivity extends Activity {

    /*
     * Some code has been omitted for brevity!
     * This method gets called upon a successful login.
     */

    public void updateParseInstallation() {
        String currentUserId = ParseUser.getCurrentUser().getObjectId();

        ParseInstallation installation;
installation.put("userId", ParseUser.CurrentUserId);

      ParseInstallation.getCurrentInstallation().saveInBackground();

    }

}
InviteActivity.java
import android.app.Activity;
import android.os.Bundle;
import com.parse.ParseInstallation;
import com.parse.ParseQuery;

public class InviteActivity extends Activity {

    /*
     * Some code has been omitted for brevity!
     * This method gets called when an invitation is sent.
     */

    public void sendPushNotifications(String playerId) {
        ParseQuery<ParseInstallation> pushQuery;

    }
}

1 Answer

Jack Middlebrook
Jack Middlebrook
19,746 Points

You should assign the ParseInstallation.getCurrentInstallation() to the ParseInstallation installation variable:

ParseInstallation installation = ParseInstallation.getCurrentInstallation();

Then you can continue with the put() method.

For the parameters to the put method the currentUserId is already stored above with

String currentUserId = ParseUser.getCurrentUser().getObjectId();

so no need to call "ParseUser.CurrentUserId" and you can just use currentUserId.

Also, if you are just on the task 2 then you can wait to save until task 3 in which case you will again use the ParseInstallation installation variable that the currentUserId was saved in.

Hope that helps.

Thanks for the help. I got it working just fine