2014-04-22 2 views
2

사용자가 내 앱을 시작할 때 다음을 달성하려고합니다.사용자가 로그인했는지 확인하는 동안 활동 시작을 중지하는 방법은 무엇입니까?

1- 사용자가 로그인하지 않은 상태에서 로그인 화면을 표시합니다. 2- 사용자가 이미 계정을 만들었고 유효한 토큰이있는 경우 시작 화면을 표시합니다.

이 목적으로 여기 http://www.udinic.com/에있는 자습서를 기반으로 사용자 지정 인증자를 구현했습니다.

코드가 작동하지만 내 문제는 현재 활동 UI가 잠깐 나타난 후 내 AccountAuthenticator에서 제공하는 계정 추가 UI로 전환된다는 것입니다. 어떻게 해결할 수 있습니까? 내 사용자가 응용 프로그램의 시작에 로그인하기

@Override 
public void onStart(){ 
    super.onStart(); 
    getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS); 


} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    mAccountManager = AccountManager.get(this); 
} 


    /** 
* Get an auth token for the account. 
* If not exist - add it and then return its auth token. 
* If one exist - return its auth token. 
* If more than one exists - show a picker and return the select account's auth token. 
* @param accountType 
* @param authTokenType 
*/ 
private void getTokenForAccountCreateIfNeeded(String accountType, String authTokenType) { 
    final AccountManagerFuture<Bundle> future = mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, 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); 
         showMessage(((authtoken != null) ? "SUCCESS!\ntoken: " + authtoken : "FAIL")); 


        } catch (Exception e) { 
         e.printStackTrace(); 
         showMessage(e.getMessage()); 
        } 
       } 
      } 
    , null); 
} 

힘 :

는 코드입니다. 여기 http://www.udinic.com/에있는 자습서를 기반으로 사용자 지정 인증자를 구현했습니다.

답변

1

인증 방법이 비동기 적이므로 UI가 표시되지 않도록 할 수 없습니다. 인증 상태를 확인한 라우터/스플래시 화면 Activity을 구현 한 다음 사용자가 로그인 한 경우 로그인 Activity 또는 실제 Activity을 시작합니다. 라우터 Activity을 매니페스트의 nohistory으로 설정했는지 확인하십시오.

Activity 하나로 유지하려면 레이아웃 상단에 배치되는 전체 화면로드 표시기가 있어야하며 표시 할 레이아웃을 파악한 후에는 사라집니다.