我正在使用Firebase,并且在登录屏幕中我有一个方法,当用户输入正确的登录凭据时(该方法启动Firebase线程以获取主屏幕所需的所有信息) ),当主屏幕打开时,我需要等到该方法完成,我需要某种标志或东西,让我粘贴你的代码:
Login.java:
mProgress.setMessage("Verificando Datos Usuario...");
mProgress.show();
mAuth.signInWithEmailAndPassword(usuario, pass)
.addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(Login.this, "Los Datos administrados no son correctos",
Toast.LENGTH_SHORT).show();
mProgress.dismiss();
} else{
Toast.makeText(Login.this, "Bienvenido... ",
Toast.LENGTH_SHORT).show();
AdminFirebase.loadAdmin(task.getResult().getUser());
mProgress.dismiss();
Intent intento=new Intent(Login.this, Principal.class);
startActivity(intento);
}
}
});
AdminFirebase.java:
public static void loadAdmin(FirebaseUser user){
DatabaseReference userRef=adminRef.child(user.getUid());
userRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Administrador administrador=dataSnapshot.getValue(Administrador.class);
Sesion.admin=administrador;
Sesion.admin.loadTaxis();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
我需要等待完成在Taxifirebase.java类上运行它的方法:
public static void loadTaxis(List<String> chapas){
for (String chapa :chapas) {
DatabaseReference taxiref=childRef.child(chapa);
taxiref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Taxi taxi=dataSnapshot.getValue(Taxi.class);
Sesion.taxis.add(taxi);
}
}
提前致谢。