1

I'm using the stackmob API in an android project and it seems that the callbacks are not called on successful completion. The function that I need to have work correctly is the login function. I have the following function that is called from an onClick handler:

    private void logIn()
    {
        Map params = new HashMap();
        EditText e = ( EditText ) findViewById( R.id.userNameEditText );
        params.put( "username", e.getText().toString() );
        e = ( EditText ) findViewById( R.id.passwordEditText );
        params.put( "password", e.getText().toString() );
        m_stackmob.login( params, new StackMobCallback()
        {
            @Override
            public void success( String response )//<--never called
            {
                Log.d( TAG, response );//<--Never see this in the log
                setLoggedIn();//<--UploadActivity member function never fires
            }

            @Override
            public void failure( StackMobException e )
            {
                Log.d( TAG, e.getMessage() );
                Toast.makeText( TimeTrackerUploadActivity.this, 
                                e.getMessage(), 
                                Toast.LENGTH_LONG ).show();        
            }
    } );
} 

When the function is called, I'm logged into stackmob and can post data, but the callback success function is never called. Does anyone know why this is, or how to fix it? Am I doing something wrong? I need to know if the login succeeds to set state in the activity. Thank you.

While I did not find an answer for this, I did find a workaround. It's not as clean as having the callback work, but it get's the job done. Here it is.

    private void logIn()
    {
        Map params = new HashMap();
        EditText e = ( EditText ) findViewById( R.id.userNameEditText );
        params.put( "username", e.getText().toString() );
        e = ( EditText ) findViewById( R.id.passwordEditText );
        params.put( "password", e.getText().toString() );
        StackMobRequestSendResult result = m_stackmob.login( params, new StackMobCallback()
        {
            @Override
            public void success( String response )
            {}

            @Override
            public void failure( StackMobException e )
            {
                Log.d( TAG, e.getMessage() );
                Toast.makeText( TimeTrackerUploadActivity.this, 
                                e.getMessage(), 
                                Toast.LENGTH_LONG ).show();
            }
        } );

        RequestSendStatus status = result.getStatus();
        if( status.compareTo( RequestSendStatus.SENT ) == 0 )
        {
            Log.d( TAG, "Login success detected!!!" );
            setLoggedIn();
        }
        else
        {
             //failure callback works and can handle this
        }
    }

Regards, Joseph

jdwieber
  • 37
  • 1
  • 6
  • I added a work around for the issue to the above question. I'm still interested in knowing if I'm using the callback incorrectly, or expecting too much. – jdwieber Apr 02 '12 at 14:35

1 Answers1

2

Your workaround isn't really working. The StackMobSendResult just tells you that the request has been sent, not that it's been processed successfully. What you really want is the callback function.

Your original code looks right and the same code works for me. Could you try with the very recent latest sdk (0.4.2)? https://github.com/downloads/stackmob/StackMob_Android/stackmob-android-v0.4.2.zip If it doesn't work, you'll be able to enable debug logging by adding StackMobCommon.LOGGING_ENABLED = true; to your onCreate right before calling StackMobCommon.init. Do that and you should see some messages tagged StackMob in your Logcat, can you post them here? Thanks

Douglas Rapp
  • 360
  • 2
  • 5
  • I'm using 0.4.2 downloaded from the stackmob website. I'll pull it from github and do as you said. I'll post my results. Also, thanks for the info about the return value.. – jdwieber Apr 03 '12 at 14:02
  • Ok, I was wrong. I have sdk 0.4.1. When I use the version from the link above (0.4.2) The login callback works. Thank you Douglas. – jdwieber Apr 03 '12 at 21:15