Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. How to get string value after updating string

How to get string value after updating string

Scheduled Pinned Locked Moved Android
databasequestionandroidhelptutorial
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15037009
    wrote on last edited by
    #1

    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");
    
    D 1 Reply Last reply
    0
    • M Member_15037009

      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");
      
      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups