Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – Kotlin keep reference to class and update

Posted on November 14, 2022

Solution 1 :

It looks like you are assigning the result in different thread, add @Volatile (java volatile) so that other threads can see the changes

@Volatile var profilePictureUrl: String = ...

Problem :

I’m confused around member reference in Kotlin. I have a custom class that once I create an instance of it i execute api work. I keep a list of these instances of the class – once the api work has completed I want the list of the instances to be updated. In swift reference types handle this but I’m unsure how to implement in Kotlin.

So my code:
MY custom class:

    class MyCustomClass(var firstName: String, var lastName:String, var profilePictureUrl_String= EMPTY_STRING){
        
        fun getUsersProfilePicture(){
//api code executed here to fetch the users profile picture
            profilePictureUrl = api result
        }
    }

when I create an instance of this object I add to an array list in my viewmodel

var myClass = MyCustomClass("firstName", "lastName")
myClass.getUsersProfilePicture()
list.add(myClass)

The api function executes fine but the instance in my list is not updated with this value.
How do I update the object in my list once the api task has returned with the correct image?

Comments

Comment posted by IR42

Is

Comment posted by nt95

Thanks for your reply!! @Volatile was exactly what I needed! You should answer the question and I will mark it as the correct answer! Thank you so much ☺️

READ  [ANSWERED] java - IDs to IDs linking on menus of drawer and toolbar to nav_graph not working
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress