I have some data stored in a database. In this case, users of the application.
I want to get all my information and place the layout of my application, so I need the data to be extracted using the function of onCreatemy layout class in order to display it when this layout changes.
I know about AsyncTaskand Volleyto execute asynchronous requests to my API, but in most cases not all users will be displayed on the layout, because they have not yet been extracted at the time the layout was displayed.
I also searched, and it seems that there are some ways (which sometimes seem to be workarounds) to make both AsyncTaskand Volleysynchronous, but they block UIThread.
I know the difference in requests asynchronousand synchronouswhy the second is blocking the application, so I have some questions.
- Is it always recommended to use asynchronous requests?
- If synchronous queries are bad, what is used when you need the data you retrieved from your database to be displayed at the same time as the layout?
- If I want this data to be available for the entire layout class, how can I handle it? I need to display data on the screen when rendering the layout, but I also want to do some things with it, so if I try to use it anywhere from the
onResponseVolley request method , I always get it null. Something like "preloading" data.
Thanks in advance!
source
share