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'
任意のデータベース呼び出しが動作するかを解きますか? ref変数の作成方法を教えてください。 –
ああ、それは古い方法です!新しいSDKは同じページの「後」ボックスです。私はある人が編集していたことに幾分驚いています!古いSDKと新しいSDKに依存していますか? –
はい私は新しいものを見てきました –