error handling in synchronous calls while saving in android

Hi, please clarify how i am supposed to handle errors while making synchronus calls in android api.
For example in the code below,

..... 
contributions.setContributor_name( mCurrentUser );
    contributions.setContribution_amount( mAmount );
    contributions.setFor_month(mFor_month);
    contributions.setBalance_carried_forwad( balance );
    contributions.setId_no( mUserIdNo );
    contributions.setPayment_mode( mPaymentMode );
}

@Override
protected Contributions doInBackground( Integer... params )
{
    for (; count <= params[0]; count++) {
        try {
            Thread.sleep(1000);
            publishProgress(count);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return contributions.save();
}

@Override
protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);
    progresBarView.setProgress( values[0] );
}

@Override
protected void onPostExecute(Contributions contributions) {
    emptyFields();
    showToast( getResources().getString( R.string.save_success ) );
    progresBarView.setVisibility( View.GONE );
}
.......
When i a user saves a duplicate value i need to handle the error and prompt him .. how do i catch or handle the response??
Thank you.


I can’t see where you call any synchronous Backendless method. Could you please clarify?

in in the function doInBackground() there’s return contributions.save()… which returns the object of Contribution type if saved succefully. But when there’s is an error e.g duplicate entry saving, i cant handle it or tell what is returned. Here’s the example. I want to alert user on that duplicate message…

You should wrap it into try-catch block and handle in the way you need.

Sorry i dont seem to understand you… Where exactly… should i wrap the return contributions.save() OR postExecute() ??

You should wrap a synchronous call to Backendless.

Thank you Sergey for you Help. It’s okay now.
:slight_smile: