OSDN Git Service

Merge "b/2500471 Pressing back after setting up account will now enter Calendar"
authorErik <roboerik@android.com>
Fri, 12 Mar 2010 00:26:06 +0000 (16:26 -0800)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 12 Mar 2010 00:26:06 +0000 (16:26 -0800)
src/com/android/calendar/LaunchActivity.java

index 26e767a..5dcb4f4 100644 (file)
@@ -59,18 +59,29 @@ public class LaunchActivity extends Activity {
                 // 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();