-1

In the code section below, I wanted to test the data in the log, but I get a null value, so I cannot access data from outside. I would be very glad if you could help.

I want to get value from outside. I can't do it. I'm new, please help with this.

Thanks.

public class MyApplication extends Application {

    AppLangSessionManager appLangSessionManager;
    public String isvip;
    public Boolean isads;

    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseMessaging.getInstance().subscribeToTopic("all");
        appLangSessionManager = new AppLangSessionManager(getApplicationContext());
    }

    public void isVip() {
        FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        String email = user.getEmail();

        CollectionReference collectionReference = firebaseFirestore.collection("Users");
        collectionReference.whereEqualTo("user_mail",email).addSnapshotListener(new EventListener<QuerySnapshot>() {
            @Override
            public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException e) {

                if (e != null)
                {
                    Toast.makeText(MyApplication.this,e.getLocalizedMessage().toString(),Toast.LENGTH_LONG).show();
                }

                if (value != null)
                {
                    for (DocumentSnapshot snapshot : value.getDocuments())
                    {
                        Map<String,Object> data = snapshot.getData();
                        Boolean deger = (Boolean) data.get("user_vip");
                        isvip = "OK";
                    }
                }
            }
        });

        System.out.println("Değer "+isvip);
    }
}

1 Answers1

0

Try using an onCompletionListener instead of onEvent. Then set your System.out.println() inside your onCompletionListener brackets. Basically it takes a second to find the data in firebase and by the time it does you've already passed the println line.

Trevor Soare
  • 120
  • 8