3
A
답변
7
해결 방법은 동기화 결과에 지연을 설정하는 것이 었습니다. 이 지연 후 동기화가 다시 시작됩니다.
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;
}
-2
을 실패 할 때, 나는 당신이 Toasts
간단한 토스트입니다 원하는 것을 생각 Google 계정과 같은 메시지가 표시되고 보여주고 싶은 :
Toast.makeText(context, text, duration).show();
text
은 상상할 수있는 텍스트입니다. duration
중 하나 Toast.LENGTH_SHORT 또는 Toast.LENGTH_LONG가 토스트에 그림과
더 복잡한 방법 (토스트는 볼 수 sahll 기간에 따라 다름)입니다 : (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>
그리고 당신의 코드 :
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();
이 메시지를 표시하는 방법이나 동기화가 실패했음을 알기 위해 어떤 예외를 잡아야하는지 묻는 중입니까? –
나는 예외를 잡는'onPerformSync'에'catch' 블록을 가지고 있고, 그 블록들에는'syncResult.stats.numParseExceptions ++'와'syncResult.stats.numIoExceptions ++'가 있습니다. 이것이 예외를 잡는 올바른 방법이되기를 바랍니다. 그렇다면 메시지를 표시하는 방법이 필요합니다. – nikmin