0

In my app, I have an Activity that display a Calendar.

Besides the fact to display a basic calendar (day, month, year), I need also to display different times, such sunrise and sunset...

To get accurate times, I fixed the TimeZone with the Google TimeZone API that is a webservice that return the TimeZone by longitude and latitude.

For who that doesn't know, Android avoid to do network operation in the main thread, that's why I need to get the TimeZone in other thread and then display the calendar in the UI.

In the android framework, the best way to update the UI from a thread is to use the AsyncThread but that this is a asynchronous thread the activity displays my calendar before it fixes the timezone.

How can you advice me to, on one side get the TimeZine from the webservice with a AsyncTask (or something else) and form the scd side to display the appropriate calendar times ??

Eliel Haouzi
  • 607
  • 1
  • 6
  • 17
  • Run the Http Get request in 'doOnBackground' of the Asynctask. and in 'onPostExecute' set the calendar view. – asloob Nov 30 '12 at 10:20

2 Answers2

0

AsyncTask is meant for short running background tasks. I really suggest you use a service to perform a Network Request on Android.

Did you have a look at RoboSpice ?

Snicolas
  • 37,840
  • 15
  • 114
  • 173
0

Set your calendar on onPostExecute() after web request is finished.
I recommend you to use a spinner to make your application looks good.
Show your spinner when loading data, and dismiss it on onPostExecute().

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103