2017-08-24 91 views
0

我想爲使用Firebase UI的Firebase用戶登錄調用AuthStateListener,但是在執行活動時不調用該方法。我以前做過同樣的過程,不同的應用下面是代碼:FIrebase AuthStateListener沒有被調用

mAuthListener = new FirebaseAuth.AuthStateListener() { 
     @Override 
     public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
      FirebaseUser firebaseUser = firebaseAuth.getCurrentUser(); 

      if (firebaseUser != null) { 
       Log.d(TAG, "In SignedinFirebaseMethod"); 

      } else { 
       startActivityForResult(
         AuthUI.getInstance() 
           .createSignInIntentBuilder() 
           .setIsSmartLockEnabled(false) 
           .setProviders(AuthUI.GOOGLE_PROVIDER, 
             AuthUI.EMAIL_PROVIDER) 
           .build(), 
         RC_SIGN_IN); 
      } 
     } 
    }; 

這裏是搖籃代碼:

android { 
compileSdkVersion 25 
buildToolsVersion "24.0.1" 
defaultConfig { 
    applicationId "com.example.hamid_pc.auctionapp" 
    minSdkVersion 16 
    targetSdkVersion 25 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
} 

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
    exclude group: 'com.android.support', module: 'support-annotations' 
}) 
compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.google.firebase:firebase-database:10.0.1' 
compile 'com.android.support:recyclerview-v7:25.3.1' 
compile 'com.android.support:design:25.3.1' 
compile 'com.android.support:support-v4:25.3.1' 
compile 'net.danlew:android.joda:2.9.9' 
compile 'com.google.firebase:firebase-storage:10.0.1' 
compile 'com.google.firebase:firebase-auth:10.0.1' 
compile 'com.firebaseui:firebase-ui:1.1.1' 
testCompile 'junit:junit:4.12' 
} 

apply plugin: 'com.google.gms.google-services' 
+0

後您的應用程序模塊的build.gradle文件時,我並沒有安裝監聽器被註銷。 –

+0

@BobSnyder我已經更新了代碼幷包含了gradle代碼 – Pheonix

+0

我沒有在那裏看到問題。您的設備是否安裝了兼容版本的Google Play服務?當您的應用初始化時,您是否在logcat中看到'W/GooglePlayServicesUtil:Google Play服務已過期'消息? –

回答

0

嘗試用火力做AUTH之前註冊的監聽器。有可能你遲到了聽衆。

抽象無效onAuthStateChanged(FirebaseAuth AUTH)

,此方法被調用在UI線程上的認證狀態的改變:聽衆已經註冊右後

  • 當用戶登錄時

  • 噹噹前用戶在當前用戶更改
+0

我不認爲註冊聽衆是問題 – Pheonix

+0

你可以在活動中顯示流程,在什麼時候調用firebaseauth.signin –

+0

該方法在OnCreate方法中調用,代碼高於 – Pheonix

-2

我在代碼中發現了錯誤開始的片段

@Override 
public void onStart() { 
    super.onStart(); 
    mAuth.addAuthStateListener(mAuthListener); 
}