No code, just an idea. Originally, in addition to avoiding anr for asynchronous network requests, there is another important reason, which is to achieve parallel operations. And the effect you want is actually the effect of synchronous execution. So the implementation method is to use the handler to process the data, and use a loading view to isolate user operations. Process it after getting the callback.
After you request the data, just version 用msg.obj=version装进去,然后在OnCreate中handleMessage(Message msg)get the version and continue to request the data asynchronously
The answers above are all good. Let me add something extra. Okhttp in the square family is very easy to use. It will be even easier to use if retrofit of the family itself is added. Retrofit+Rx is very good at handling between threads and exception handling is also very good.
Use Handler:
Recommend rxjava+retrofit
No code, just an idea.
Originally, in addition to avoiding anr for asynchronous network requests, there is another important reason, which is to achieve parallel operations. And the effect you want is actually the effect of synchronous execution.
So the implementation method is to use the handler to process the data, and use a loading view to isolate user operations. Process it after getting the callback.
After you request the data, just
version
用msg.obj=version
装进去,然后在OnCreate中handleMessage(Message msg)
get the version and continue to request the data asynchronouslyThe answers above are all good. Let me add something extra. Okhttp in the square family is very easy to use. It will be even easier to use if retrofit of the family itself is added. Retrofit+Rx is very good at handling between threads and exception handling is also very good.