0

説明を更新サインイン/アクティビティでデータベースに接続できません。 Firebase - 9.0.0

どのようにユーザーのサインアップと同時にデータベースにユーザを送ることができます。私の古いコードで働いていたが、もう何も分からなかったのは何ですか?

ユーザーがログインしているときや、mainActivy()でユーザーのジオタグを開始したときにデータベースとの接続が確立されます。しかし、ユーザーがサインアップしてログインしたときにすぐに保存する必要があります。そのため、ログインアクティビティにコードの何かが間違っています。

ログイン・アクティビティー:

mAuthListener = new FirebaseAuth.AuthStateListener() { 
    @Override 
    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
     FirebaseUser user = firebaseAuth.getCurrentUser(); 
     if (user != null) { 
      // User is signed in 
      Log.d("TAG", "onAuthStateChanged:signed_in:" + user.getUid()); 

      DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); 

      // Authenticated successfully with authData 
      Map<String, Object> map = new HashMap<String, Object>(); 
      map.put("email", email); 
      ref.child("users").child(user.getUid()).updateChildren(map); 


      Intent intent = new Intent(LoginActivity.this, MainReal.class); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
      startActivity(intent); 

     } else { 
      // User is signed out 
      Log.d("TAG", "onAuthStateChanged:signed_out"); 
     } 
    } 
}; 

依存

compile "com.google.firebase:firebase-database:9.0.0" 
compile 'com.google.firebase:firebase-auth:9.0.0' 
compile 'com.firebaseui:firebase-ui-database:0.4.0' 
compile 'com.firebaseui:firebase-ui-auth:0.4.0' 

enter image description here

+0

任意のデータベース呼び出しが動作するかを解きますか? ref変数の作成方法を教えてください。 –

+0

ああ、それは古い方法です!新しいSDKは同じページの「後」ボックスです。私はある人が編集していたことに幾分驚いています!古いSDKと新しいSDKに依存していますか? –

+0

はい私は新しいものを見てきました –

答えて

0

問題はString emailnull

であるということでした

次のように問題

map.put("email", user.getEmail()); 
関連する問題