How to show sync error message

I created a contacts sync adapter. Everything works fine, but I need one more. If sync fails for some reason, I want to display a message similar to the one displayed in Google account when sync failed.

Screenshot

+3


source to share


2 answers


The solution was to set a delay on the sync result. After this delay, synchronization will restart.



try {
    DO THE SYNCHRONIZATION
} catch (AuthenticationException e) {
    Log.e(TAG, "AuthenticationException");
    syncResult.stats.numAuthExceptions++;
    syncResult.delayUntil = 180;
} catch (ParseException e) {
    Log.e(TAG, "ParseException");
    syncResult.stats.numParseExceptions++;
} catch (IOException e) {
    Log.e(TAG, "IOException");
    syncResult.stats.numIoExceptions++;
    syncResult.delayUntil = 180;
}

      

+7


source


I Think You Want Toasts

Simple toast:

Toast.makeText(context, text, duration).show();

      

text

is, as you can imagine, the text you want to display. duration

is Toast.LENGTH_SHORT or Toast.LENGTH_LONG (depends on how long Toast sahll will be displayed)



More sophisticated approach with image in toast: (sync_toast_lo.xml)

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/SynctoastLayout"
    android:background="@android:color/black">

  <ImageView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:src="@drawable/your_logo"
    android:layout_toLeftOf="@+id/textView"
    android:layout_margin="5dip"
    android:id="@+id/syncLogo">
  </ImageView>

  <TextView
    android:id="@+id/syncFailedText"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="The sync has failed!"
    android:gravity="center"
    android:textColor="@android:color/white">
  </TextView>
</RelativeLayout>

      

And in your code:

LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.Sync_toast_lo,
                               (ViewGroup) findViewById(R.id.SynctoastLayout));

Toast toast = new Toast(this);
toast.setView(view);
toast.show();

      

-2


source







All Articles