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