1

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!

nwalke
  • 3,092
  • 5
  • 32
  • 59
anonymous
  • 1,250
  • 5
  • 19
  • 36

3 Answers3

2

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

207
  • 3,794
  • 2
  • 23
  • 22
1

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

ngesh
  • 13,241
  • 4
  • 43
  • 59
1

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

Community
  • 1
  • 1
Ronak Mehta
  • 6,010
  • 5
  • 41
  • 68