@Override
 protected void onResume() {
   super.onResume();
   // if don't have an account, ask user to choose account
   if (credential.getAccountName() == null) {
     chooseAccount();
   }
 }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   // enable logging
   Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL);
   // view and menu
   setContentView(R.layout.calendarlist);
   listView = (ListView) findViewById(R.id.list);
   registerForContextMenu(listView);
   // Google Accounts
   credential = GoogleAccountCredential.usingOAuth2(this, CalendarScopes.CALENDAR);
   SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
   credential.setAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
   // Calendar client
   client =
       new com.google.api.services.calendar.Calendar.Builder(transport, jsonFactory, credential)
           .setApplicationName("Google-CalendarAndroidSample/1.0")
           .build();
   // if we already have an account, go ahead and fetch calendars now
   if (credential.getAccountName() != null) {
     AsyncLoadCalendars.run(this);
   }
 }