Currently, my app starts with a menu. Once a menu item is clicked, it starts a Activity which grabs content from an online API.
The problem I am having is, once the menu item is clicked, the application waits until the http request and response is complete before it displays the activity.
My Question is, How can I have the Activity display instantly with the layout and static View. Then once the activity is loaded, then I start fetching data from an API?
Why run after when you can run concurrently!!
Use an
AsyncTaskin youronCreate()/onResume()method.In your implementation of
MyTask, put your long running code (the data fetched from the http request) into thedoInBackground()method. Once thedoInBackground()method returns, you can update yourViewinonPostExecute().Also, take a look at Painless Threading, as there is lots of helpful android threading information in there.