As you are using firebase , I do not think you need to use SharedPreferences in this case, as you want to set a nickname strong> immutable if it does not exist, you will only need to apply logic directly using firebase . SharedPreferences is useful in case of saving application configuration (such as themes, colors, splash screens, etc). You can read a bit more about SharedPrefences here:
Basically, you will need to check if the user has a nickname, if he has one, you do not show the nickname entry screen, otherwise you show.
Your node will probably look something like this:
{
"Users": [
{
"userUUID/Key": {
"name": "Corey",
"apelido": ""
}
}
]
}
And the logic applied 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 terminates the registration but does not set a nickname, you can check if the nickname was set as soon as the application opens, with that same logic, causing the user to come back to set it. This can be when the app is opened or when the user logs in.