How to get string value after updating string
-
Today I come to you with one question - I am currently creating an Android application that works with the firestore and implemented a class that checks the account type. Everything works fine, however I would now like to get the value of "typeOfAcc" from this class in a different class as it will be the path to my document in the database, however, there is one condition - the path must be downloaded only after the data is downloaded from the database and based on it it will be determined whether the account type should be changed to "Trainers". Anyone have any idea? All my attempts so far have ended with the second class just getting this string before changing its value, resulting in no access to data. Checking the logs, everything is fine, the value changes, but unfortunately after getting the value. Thanks in advance for your help!
```
public class UserValid
{
String typeOfAcc = "Podopieczni";
FirebaseFirestore fStore;
FirebaseAuth fAuth;
DocumentReference documentReference;
List itemList = new ArrayList<>();
String userID;public UserValid() { Log.d("TAG", "Błąd, wybrano konstruktor bez argumentów"); } //Metoda sprawdzająca jaki typ konta jest aktualnie obsługiwany // Jeśli wartość true - konto podopiecznego, wartość false - konto trenera; public UserValid(FirebaseAuth fAuth, FirebaseFirestore fStore) { userID = fAuth.getCurrentUser().getUid(); this.fAuth = fAuth; this.fStore = fStore; documentReference = fStore.collection("Podopieczni").document(userID); readData(new FirestoreCallback() { @Override public void onCallback(List list) { if(itemList.get(0) == null) { typeOfAcc="Trenerzy"; Log.d("TAG", itemList.toString()); } } }); } private void readData(FirestoreCallback firestoreCallback) { //DocumentReference docRef = db.collection("cities").document("SF"); documentReference.get().addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { //for(DocumentSnapshot document : task.getResult()) { String itemName = task.getResult().getString("Imie");
-
Today I come to you with one question - I am currently creating an Android application that works with the firestore and implemented a class that checks the account type. Everything works fine, however I would now like to get the value of "typeOfAcc" from this class in a different class as it will be the path to my document in the database, however, there is one condition - the path must be downloaded only after the data is downloaded from the database and based on it it will be determined whether the account type should be changed to "Trainers". Anyone have any idea? All my attempts so far have ended with the second class just getting this string before changing its value, resulting in no access to data. Checking the logs, everything is fine, the value changes, but unfortunately after getting the value. Thanks in advance for your help!
```
public class UserValid
{
String typeOfAcc = "Podopieczni";
FirebaseFirestore fStore;
FirebaseAuth fAuth;
DocumentReference documentReference;
List itemList = new ArrayList<>();
String userID;public UserValid() { Log.d("TAG", "Błąd, wybrano konstruktor bez argumentów"); } //Metoda sprawdzająca jaki typ konta jest aktualnie obsługiwany // Jeśli wartość true - konto podopiecznego, wartość false - konto trenera; public UserValid(FirebaseAuth fAuth, FirebaseFirestore fStore) { userID = fAuth.getCurrentUser().getUid(); this.fAuth = fAuth; this.fStore = fStore; documentReference = fStore.collection("Podopieczni").document(userID); readData(new FirestoreCallback() { @Override public void onCallback(List list) { if(itemList.get(0) == null) { typeOfAcc="Trenerzy"; Log.d("TAG", itemList.toString()); } } }); } private void readData(FirestoreCallback firestoreCallback) { //DocumentReference docRef = db.collection("cities").document("SF"); documentReference.get().addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { //for(DocumentSnapshot document : task.getResult()) { String itemName = task.getResult().getString("Imie");
Member 15037009 wrote:
...I would now like to get the value of "typeOfAcc" from this class in a different class...
If it's a peer class, can you store it in a preference? The "receiving" class can monitor any changes to the preference and only do something when it changes.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles