guys, can you help me? this is my first trying thi...
# android
d
guys, can you help me? this is my first trying this in Kotlin. I have a function where i need to use the result from the function in this screenshot, why its gonna jump to line 201 after line 189? Why its not run what inside result.failure or result.success first? edit : because of that what i got is empty string when call this function from other function.
j
apparently there is an async task going with post (network operations should work this way). That means that when calling loadProfile and reaching post, a new thread/coroutine is being created, so it will immediately go to return username
you always need a notify/callback funtion to react when the result is calculated
are you following a clean arch?
d
what is a clean arch? and yes i think its because async too, but what should i do?
j
working in frontend and reaching backend requires to implement async operations
let me find an example
do you use liveData/ViewModel?
this is what Google recommends working with liveData + ViewModel
if not, there is a common arch ModelViewPresenter (MVP)
d
i doesn't use pattern @Jorge R but i will try it, thanks. currently i just make a simple solution for this with making its a global var and assign the value in onCreatedView function.
j
that is wrong
my recommendation is to find a good architecture and follow it
it is a solution for a know problem
the worst part on learning how to code in Android is the async task part
how to avoid main thread block
and post result to it
keep in mind that all operations that take more than few seconds will block UI thread and will make your app unresponsive
so you need to run your operations in another thread/coroutine out of the UI one
d
@Jorge R my bad, i am still new, do you have some article or guide for something like this? i prefer something like that over documentation afterall.
its seems interesting, but if you have recommendation, its became more interesting ! 😄
this is a known project where you can check the architecture
there are two basic arch, MVP and MVVM
I would check which one fits you more and go for it
and to do that, lot of reading and googling
sorry but you need to read and learn to understand why, best way to become expert and good
d
@Jorge R ah my bad jorge, i doesn't notice your reply, but thanks god its solved already 😄
👍 1