delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

ResultListener is not working good inside View.OnClickListener #67

Closed cristianhoyos66-zz closed 8 years ago

cristianhoyos66-zz commented 8 years ago

Hi, thank you again for this library, but i have a problem with this:

I am calling a method of this way

private View.OnClickListener signin = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionSignin();
        }
    };

private void actionSignin() {
        String usernameEmail = txtEmail.getText().toString();
        String password = txtPassword.getText().toString();
        ResultListener rLSignin = new ResultListener() {
            @Override
            public void onSuccess(String s) {
                redirectServicesActivity();
            }

            @Override
            public void onError(String s, String s1, String s2) {
                System.out.println("S22" + s + "s33" + s1 + "s44" + s2);
            }
        };
        mMeteor.loginWithUsername(usernameEmail, password, rLSignin);
    }

and the ResultListener sometimes work. I try to do a login with username and password that can't be found on database, and it should must to execute this line System.out.println("S22" + s + "s33" + s1 + "s44" + s2); but sometime is executed. All process in actionSignin() method is executed, but ResultListener sometimes.

Do you know why is this happening or is this a bug?

Thank you

ocram commented 8 years ago

Thanks for this report!

So what is the problem exactly?

Are both onSuccess and onError of the ResultListener called sometimes, but not always?

cristianhoyos66-zz commented 8 years ago

The problem persist with both onSucess and onErrror

I am doing this:

LoginActivity

@Override
    protected void onStart() {
        super.onStart();
        ConnectionDDP connectionDDP = new ConnectionDDP(this);
        mMeteor = connectionDDP.getmMeteor();
        for (int i = 0; i < 10; i++) {
             mMeteor.loginWithUsername("prueba", "pruebapass", new ResultListener() {
            @Override
            public void onSuccess(String s) {
                redirectServicesActivity();
            }

            @Override
            public void onError(String s, String s1, String s2) {
                System.out.println("S22" + s + "s33" + s1 + "s44" + s2);
            }
        });
       }
    }

username: "prueba" and password: "pruebapass" don't exist on bd and in fact execute this line System.out.println("S22" + s + "s33" + s1 + "s44" + s2); 10 times

but the problem arises when I try to do a login with this mMeteor.loginWithUsername inside a View.OnClickListener that onSucces and onError sometimes executes their respective process, but not always that I do a click on the login button.

thank you.

ocram commented 8 years ago

So you're saying that the ResultListener usually works without any problems, but when used inside of an OnClickListener, it does not work (reliably). Right?

cristianhoyos66-zz commented 8 years ago

Yes, I do.

I don't know why is it happening :/

ocram commented 8 years ago

Please use log statements in the first line of private void actionSignin, public void onClick, public void onSuccess and public void onError each.

This way you can verify if these parts of the code are executed at all.

I'm not sure why things should work in onStart but not inside an OnClickListener. Both are executed on the main (UI) thead.

cristianhoyos66-zz commented 8 years ago

I was doing some tests and I gave with the solution. Afortunately It is not a bug.

The problem was my emulator, but I didn't think that it could happen hehe So I changed the emulator and I tested on a real device and it works good on both.

Thank you so much.