How can Firebsae Realtime NOT load previous data after logging out of the account?

Asked

Viewed 20 times

0

At the beginning of conversation, I am very new in android Java development, however I have a problem with firebase Altime in my application. I turned on . setPersistenceEnabled(true); for it to work offline, my app also has google authentication and firebaseAuth. When I log out of the current account in the app, and immediately after logging in with another account, firebase loads the cached data from the previous account (such as values, customer data, etc.). It is necessary that I download the app fully and open it again so that it gets the data from the new account. How do I make this not happen?

// Class I enable cached persistence

public class Rdy extends Application {

@Override
public void onCreate() {
    super.onCreate();

    FirebaseApp.initializeApp(this);
    HelperClass.getDatabase();

    Picasso.Builder builder = new Picasso.Builder(this);
    builder.downloader(new OkHttp3Downloader(this, Integer.MAX_VALUE));
    Picasso built = builder.build();
    built.setIndicatorsEnabled(false);
    built.setLoggingEnabled(true);
    Picasso.setSingletonInstance(built);
}

public static class HelperClass {
    private static FirebaseDatabase firebaseDatabase;

    public static FirebaseDatabase getDatabase() {
        if (firebaseDatabase == null) {
            firebaseDatabase = FirebaseDatabase.getInstance();
            firebaseDatabase.setPersistenceEnabled(true);
            DatabaseReference.goOnline();
        }
        return firebaseDatabase;
    }
}

}

// String class of firebase

 public class RdyStrings {
private static Context context;
public static FirebaseAuth auth = FirebaseAuth.getInstance();
public static FirebaseUser user = auth.getCurrentUser();

public static DatabaseReference loadInicio = FirebaseDatabase.getInstance().getReference().child(user.getUid());
public static DatabaseReference savarPerfil = FirebaseDatabase.getInstance().getReference().child(user.getUid()).child("perfil");


public RdyStrings(Context context) {
    this.context = context;

}

}

// Minactivity - Here I log out and sync

private void logout() {

    AlertDialog.Builder o = new AlertDialog.Builder(context);
    o.setTitle("Sair da conta")
            .setMessage("Quer sair da sua conta agora " + getDefaults("nome", context) +
                    "?")
            .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
                    databaseReference.keepSynced(false);
                    auth.signOut();
                    GoogleSignIn.getClient(context, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build()).signOut().addOnCompleteListener(context, new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            Intent intent = new Intent(context, RdySplash.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intent);
                            finishAffinity();
                        }
                    });
                }
            })
            .setNegativeButton(getString(android.R.string.no), null)
            .create()
            .show();

}

private void sync() {
    RdyStrings.salvarEstoqueRef.keepSynced(true);
    RdyStrings.salvarPreVendaRef.keepSynced(true);
    RdyStrings.clientes.keepSynced(true);
    RdyStrings.vendas.keepSynced(true);
    RdyStrings.loadInicio.keepSynced(true);
    RdyStrings.savarPerfil.keepSynced(true);
    RdyStrings.caixa.keepSynced(true);
    RdyStrings.caixaValores.keepSynced(true);
}
  • You could only post the code, in which case it’s bad to have images ...

  • 1

    Thank you, I’ve edited now. Please help me.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.