Search code examples
javaandroidnetworkingwaitgoogle-nearby

How to wait in Android without locking the UI thread?


I have an app which uses nearby connections API. I connect x number of devices with a star strategy, then from a database I query a question on the "server" device, then send it forward to all other devices, but I have to wait till everyone answers the question (when someone answers, they send the answer to the "server" device, and it stores the answer in a list), so i need to wait on every devices till this list contains everyone's answer, then query an other question and so on. How can I achieve the waiting without freezing the UI? (And probably display some message till waiting, for example 3/5 players answered?)


Solution

  • You can use Threads to avoid UI freezing.

    Here you have some examples and explanations from the official Android guide: Threads

    Hope this helps you!