2014-01-11 3 views
2

내가 getAuthTokenByFeatures를 호출 할 수 있다는 사실을 알고 더 계정 내 특정 ACCOUNTTYPE에 대한 설정이없는 경우는,안드로이드 같은 관리자 및 로그인 활동

내가 원하는 정확히 어떤 내 LoginActivity를 시작 같은 관리자

를 사용하여 내 응용 프로그램에서 사용자를 인증 임

나는 onCreate 메서드 에서 LoginActivity를 시작할 때 이전 활동이 여전히 스택에 있으므로 뒤로 버튼을 눌러 이전 활동으로 돌아갈 수있는 BaseActivity를가집니다. 내가 원하는 BaseActibity.onCreate 코드는 다음과 같습니다.

AccountManager manager = AccountManager.get(getBaseContext()); 

    manager.getAuthTokenByFeatures(
      AccountGeneral.ACCOUNT_TYPE, 
      AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, 
      null, 
      this, 
      null, 
      null, 
      new AccountManagerCallback<Bundle>() { 
       @Override 
       public void run(AccountManagerFuture<Bundle> future) { 
        Bundle bnd = null; 
        try { 
         bnd = future.getResult(); 
         final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN); 

         LOGV(TAG, "GetTokenForAccount Bundle is " + bnd); 

        } catch (Exception e) { 
         LOGE(TAG, "exception while getAuthTokenByFeatures", e); 
        } 
       } 
      } 
      , null); 

질문 : 어떻게하면 그 등 동작을 비활성화 할 수 있습니까? 그것은 나를 programmaticly LoginActivity를 호출 있다면 난 단순히 당신이 뒤로 버튼 동작을 재정의 할 수 있습니다 AccountAuthenticatorActivity에 BaseActivity

+0

귀하의 기본 행동은 다른 모든 활동이 확장 된 것으로 가정합니다. 그렇다면 뒤로 버튼 동작에는 어떤 문제가 있습니까? 로그인하지 않으려면 사용자가 이전 활동으로 돌아가도록하지 않아야합니까? 이전 활동에는 시각적 신호가있어 사용자에게 특정 콘텐츠를보기 위해 로그인해야한다는 사실을 알립니다. – CChi

답변

8

에 마무리()를 호출합니다 :

@Override 
public void onBackPressed() { 
    Intent result = new Intent(); 
    Bundle b = new Bundle(); 
    result.putExtras(b); 

    setAccountAuthenticatorResult(null); // null means the user cancelled the authorization processs 
    setResult(RESULT_OK, result); 
    finish(); 
} 

지금이 취소에 반응 할 수 있습니다. 귀하의 코드에서 :

  @Override 
      public void run(AccountManagerFuture<Bundle> future) { 
       Bundle bnd = null; 
       try { 
        if (future.isCancelled()) { 
         // Do whatever you want. I understand that you want to close this activity, 
         // so supposing that mActivity is your activity: 
         mActivity.finish(); 
         return; 
        } 
        bnd = future.getResult(); 

        final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN); 

        LOGV(TAG, "GetTokenForAccount Bundle is " + bnd); 

       } catch (Exception e) { 
        LOGE(TAG, "exception while getAuthTokenByFeatures", e); 
       } 
      }