@Override
  public void onResume() {
    super.onResume();

    ContactsSync app = ContactsSync.getInstance();

    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancelAll();

    // TODO: use current/selected account (not the first one)
    Account account = ContactsSync.getInstance().getAccount();

    if (account != null) {
      if (mAuthDialog != null) {
        mAuthDialog.dismiss();
      }

      // Log.d("pref-bundle", icicle != null ? icicle.toString() : "null");
      mFragment.setAccount(account);
      if (ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) {
        if (app.getSyncFrequency() == 0) {
          app.setSyncFrequency(Preferences.DEFAULT_SYNC_FREQUENCY);
          app.savePreferences();
          ContentResolver.addPeriodicSync(
              account,
              ContactsContract.AUTHORITY,
              new Bundle(),
              Preferences.DEFAULT_SYNC_FREQUENCY * 3600);
        }
      } else {
        if (app.getSyncFrequency() > 0) {
          app.setSyncFrequency(0);
          app.savePreferences();
        }
      }
      updateStatusMessage(account, 0);
      final int mask =
          ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE | ContentResolver.SYNC_OBSERVER_TYPE_PENDING;
      mSyncObserverHandler = ContentResolver.addStatusChangeListener(mask, mSyncObserver);
    } else {
      if (mAuthDialog != null) {
        mAuthDialog.dismiss();
      }

      mAuthDialog = new Dialog(this);
      mAuthDialog.setContentView(R.layout.not_account_actions);
      mAuthDialog.setTitle("Select option");
      ((Button) mAuthDialog.findViewById(R.id.add_account_button))
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  mAuthDialog.dismiss();
                  Intent intent = new Intent(Preferences.this, AuthenticatorActivity.class);
                  startActivity(intent);
                }
              });
      ((Button) mAuthDialog.findViewById(R.id.exit_button))
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  mAuthDialog.dismiss();
                  Preferences.this.finish();
                }
              });
      mAuthDialog.setOnCancelListener(
          new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              mAuthDialog.dismiss();
              Preferences.this.finish();
            }
          });
      mAuthDialog.show();
    }
  }