How are you utilizing the firebase, I believe that it is not necessary to use the Sharedpreferences in this case, because as you want to define a nickname immutable if it does not exist, you will only need to apply the logic directly using the firebase. Sharedpreferences is useful in application configuration saving cases (such as themes, colors, splash screens, etc). You can read a little more about Sharedprefences here: Perform an action only when the app starts for the first time
Basically, you will need to check if the user has a nickname, if he has it, you do not show the nickname insertion screen, otherwise you show.
Your Ode will probably look like this:
{
"Users": [
{
"userUUID/Key": {
"name": "Corey",
"apelido": ""
}
}
]
}
And the applied logic will be:
DatabaseReference db = FirebaseDatabase.getInstance().getReference("Users");
db.child(db.push().getKey() /* UUID do usuario */).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.child("apelido").exists()) {
// o apelido já foi definido
} else {
// o apelido ainda não foi definido
}
}
@Override
public void onCancelled(DatabaseError error) {
Log.e(TAG, error.toException());
}
});
You will also be able to check if the nickname exists in other instances. What I mean is, if the user finishes the registration but does not define a nickname, you can check if the nickname was set as soon as the application is opened, with this same logic, causing the user to come back to define it. It could be when the app opens or when the user logs into your account.
you could explain me better how to create this users Node?
– Leila
https://firebase.google.com/docs/database/admin/save-data
– itscorey
We link codes above it saved on Node
users
using the user’s name. The code of my answer tells you to save through the UID, which is that code for each user of your app, understand? And so you will save all user data on that UID, which is unique.– itscorey