Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

android - Retrofit: Loading data before an Activity starts

I need to make sure that some data is loaded before the activity starts, so that I can use this data for filling a Spinner UI element. Normally I would use a repository class, LiveData and a ViewModel to store data contained by retrofit, but as far as I know this isn't possible in this particular use case (as they don't guarantee that the data is already loaded at the activity start).

I would like to keep retrofit requests inside a repository class, but currently I only get the wanted result by placing them directly in the MainActivity, and then let the retrofit call create the Activity which needs the data. This gets really messy when the underlying Activity needs data from different retrofit API calls.

Can someone tell me how do to this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...