I am completely new to Firebase and need to know how to check if my writing work was successful, because if I do not, MainActivity launches and MainActivity my Register progress.
This checks to see if Username already running, and logs in the user if it is not:
Query usernamequery = myRef.orderByChild("Username").equalTo(Username); usernamequery.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if (snapshot.exists()) { // TODO: handle the case where the data already exists editText.setError("Username taken!"); return; } else { // TODO: handle the case where the data does not yet exist myRef.child("Users").child(Username).child("Userid").setValue(user.getUid()); myRef.child("Users").child(Username).child("Username").setValue(Username); startActivity(maps); finish(); } } @Override public void onCancelled(DatabaseError databaseError) { Toast.makeText(Username.this, "Error", Toast.LENGTH_LONG).show(); } });
But I want the intention for the main activity (maps) to be launched only when myRef.child("Users").child(Username).child("Userid").setValue(user.getUid());
and the other completed with his task and successfully.
What can I do?
source share