anonymous
anonymous

Reputation: 1330

Delay after pressing a button

After I press a button, Android parse a JSON file and pick the info it needs. Until yesterday, I was using an external library created by a user and it worked perfectly. But now, I don't want to depend on him, so I've searching info about Google's GSON. I've implemented this library with no problem, but now, after pressing the button that opens a new activity there's a delay.

This delay is due to the connection and parsing that are done before the activity shows.

How can I force the app to wait the Internet connection until de Activity is shown? It's a lil bit uncomfortable because after pressing the button, it seems that the app has frozen, but after all data is loaded, the new activity appears.

Thank you in advance!

Upvotes: 1

Views: 1766

Answers (3)

Ronak Mehta
Ronak Mehta

Reputation: 5979

it is possibl;e via Handler and AsyncTask see this How to set delay in Android onClick function you will get how to use Handler and see this for Asynctask https://stackoverflow.com/questions/7644567/need-a-simple-example-for-android-asynctask

Upvotes: 1

ngesh
ngesh

Reputation: 13501

Use asyncTask.. and if server communication is a success then show the new Activity or else exit..

Upvotes: 1

207
207

Reputation: 3804

Use AsyncTask or Handler for network operations. Do never put "long time" operations into the UI thread

Upvotes: 2

Related Questions