grap
grap

Reputation: 55

Get data from database before run app

I have application which have spinner and in this spinner I have data from my database.

I use async task to get data from database, and in onPostExecute method I add to spinner this data.

My main problem is that when i run app, in my spinner data isn't available, since async task hasn't finish yet.

My question is what I have to do that my data from database are in spinner before I run my app ??

Upvotes: 0

Views: 264

Answers (2)

Kingfisher Phuoc
Kingfisher Phuoc

Reputation: 8190

Actually, the loading simple data like spinner data is very fast (it's usually 100,200 milliseconds). Then you dont have to load data before opening the app. Maybe your problem is doing too many things with AsyncTask. AsyncTasks are run in a queue, one after another one finished. So, my suggestion is using Thread for loading spinner data as:

new LoadingSpinnerDataThread().start(); // it's better if you can use RxAndroid.

Upvotes: 0

Rik1988
Rik1988

Reputation: 25

Create a layout covering the spinner displaying a loading message and set this layouts visibility to GONE in the post execute method of your asynctask

Or load your data in your main activity and start your spinner activity when the task is complete

Upvotes: 1

Related Questions