I am working on a simple Android game. On the main activity there’s a “Play” button. When the user clicks there the “Finding Other Players” activity is supposed to open, with a list of the other players he will be playing against.
That list of players is generated dynamically by connecting to a central server, so it takes 2-3 seconds.
What I want the app to do once the user clicks on “Play” is to open the background of the “Finding Players” activity, and then display the names of the other players as the server responds.
What’s happening, though, is that once you click on the “Play” button nothing happens for 2-3 seconds (while the app is getting data from the server), and then it opens the new activity window with all the data already there.
Is there a way to force the new activity background to open first, and then to work on collecting the data?
Launch the new
Activityand make sure you do all the loading on a background thread. If the main thread is busy it will appear as if its frozen even though it hasn’t.Checkout
AsyncTaskfor this, as that’s exactly what it’s for 🙂