【发布时间】:2018-01-22 18:55:49
【问题描述】:
我正在尝试以用户 ID 将用户数据保存在我的应用中。
现在,我可以保存基于“锻炼”的信息和另一个基于“锻炼详细信息”的信息。详细信息保存在“锻炼”ID 下,因此已连接。
我正在尝试将数据保存在使用 Google 登录创建的唯一用户 ID 下。
因此,当用户保存详细信息时,他/她现在只能看到自己的详细信息。我确实有正常的 Firebase 数据库规则设置。
private void addWorkout(){
String name = editTextName.getText().toString().trim();
String category = spinnerCategory.getSelectedItem().toString();
//if name not empty we save it to firebase db
if(!TextUtils.isEmpty(name)){
//make it so it saves under the user ID
FirebaseUser user = firebaseAuth.getCurrentUser();
//create a unique id for workout to save in firebase
String id =databaseWorkouts.push().getKey();
Workout workout = new Workout(id, name, category );
//set value method to save in firebase db
databaseWorkouts.child(id).setValue(workout);
Toast.makeText(this, "Workout added", Toast.LENGTH_LONG).show();
editTextName.setText("");
【问题讨论】:
标签: android firebase firebase-realtime-database firebase-authentication