samedi 23 janvier 2016

Android: Retrofit Response seems to trigger an IF Statement no matter what

So I can call my API and will give a response.

Now if my response is NOT equal to "0", then it should execute onUserFailure().

If it is equal to "0" then it should trigger onUserSuccess().

Here is my code:

destinyAPI.getMembershipId(user, new Callback<MembershipIdResponse>() {

        @Override
        public void onResponse(Response<MembershipIdResponse> response, Retrofit retrofit) {

            String id = response.body().getResponse();

            Log.d("API_CALL", "MembershipId Response! " + "(ID = " + id + ")");

            if (id != "0") {

                membershipId = id;
                onUserSuccess();

            } else {

                onUserFailure(false);

            }
        }

        @Override
        public void onFailure(Throwable t) {

            onUserFailure(true);
            Log.d("API_CALL", "MembershipId Failure.");
            t.printStackTrace();

        }
    });

Here is my Log:

D/API_CALL: MembershipId Response! (ID = 0)

Except, every time it triggers the onUserSuccess() and starts the Intent.

I am mind-boggled.

Aucun commentaire:

Enregistrer un commentaire