// If we failed to find a valid Calendar, bounce the user to the account settings
// screen. Using the Calendar authority has the added benefit of only showing
// account types that use Calendar when you enter the add account screen from here.
- // TODO bounce them to the add account screen if accessible from the public api
final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] {
Calendar.AUTHORITY
});
- startActivity(intent);
- finish();
+ startActivityForResult(intent, 0);
}
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ Account[] accounts = AccountManager.get(this).getAccounts();
+ if(accounts.length > 0) {
+ // If the only account is an account that can't use Calendar we let the user into
+ // Calendar, but they can't create any events until they add an account with a
+ // Calendar.
+ launchCalendarView();
+ } else {
+ finish();
+ }
+ }
+
private void launchCalendarView() {
// Get the data for from this intent, if any
Intent myIntent = getIntent();