瀏覽代碼

move connection (re) init from start to onResume and restore server checked flag

Andy Scherzinger 8 年之前
父節點
當前提交
4f5554861a
共有 1 個文件被更改,包括 16 次插入14 次删除
  1. 16 14
      src/com/owncloud/android/authentication/AuthenticatorActivity.java

+ 16 - 14
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -223,18 +223,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
         mIsFirstAuthAttempt = true;
 
-        // bind to Operations Service
-        mOperationsServiceConnection = new OperationsServiceConnection();
-        if (!bindService(new Intent(this, OperationsService.class),
-                mOperationsServiceConnection,
-                Context.BIND_AUTO_CREATE)) {
-            Toast.makeText(this,
-                    R.string.error_cant_bind_to_operations_service,
-                    Toast.LENGTH_LONG)
-                        .show();
-            finish();
-        }
-
         /// init activity state
         mAccountMgr = AccountManager.get(this);
         mNewCapturedUriFromOAuth2Redirection = null;
@@ -318,7 +306,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mUsernameInput.setText(loginUrlInfo.username);
             mPasswordInput.setText(loginUrlInfo.password);
 
-            if (loginUrlInfo.serverAddress != null) {
+            if (loginUrlInfo.serverAddress != null && !mServerIsChecked) {
                 onUrlInputFocusLost();
             }
         }
@@ -718,6 +706,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     public void onRestoreInstanceState(Bundle savedInstanceState) {
         super.onRestoreInstanceState(savedInstanceState);
 
+        mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED, false);
+
         // AsyncTask
         boolean inProgress = savedInstanceState.getBoolean(KEY_ASYNC_TASK_IN_PROGRESS);
         if (inProgress){
@@ -779,6 +769,18 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             }
         }
 
+        // bind to Operations Service
+        mOperationsServiceConnection = new OperationsServiceConnection();
+        if (!bindService(new Intent(this, OperationsService.class),
+                mOperationsServiceConnection,
+                Context.BIND_AUTO_CREATE)) {
+            Toast.makeText(this,
+                    R.string.error_cant_bind_to_operations_service,
+                    Toast.LENGTH_LONG)
+                    .show();
+            finish();
+        }
+
         if (mOperationsServiceBinder != null) {
             doOnResumeAndBound();
         }
@@ -1974,7 +1976,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this);
         }
 
-        if (mPendingAutoCheck) {
+        if (mHostUrlInput.getText() != null && mHostUrlInput.getText().length() > 0 && !mServerIsChecked) {
             checkOcServer();
         }
     }