Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid synchronous operations implementation #655

Open
amazuerar opened this issue Aug 15, 2021 · 0 comments
Open

Avoid synchronous operations implementation #655

amazuerar opened this issue Aug 15, 2021 · 0 comments

Comments

@amazuerar
Copy link

Dear Developer!

My name is Alejandro Mazuera-Rozo, I am a PhD Student at Universidad de los Andes, and at Università della Svizzera italiana. I am part of a research on the usage of network libraries within Android apps. As result of this we identified some code locations that might have network related problems.

In this case, we address the code locations that are related to a potential issue because of implementing synchronous operations. As you might know, synchronous requests are not recommended and its usage is discouraged.

  1. In synchronous operations, tasks are performed one at a time and only when one is completed, the following is unblocked.

  2. In asynchronous operations, you can move to another task before the previous one finishes, allowing you to deal with multiple requests simultaneously.

Moreover, by avoiding this approach, it is less likely to perform network operations on the main thread. Android requires you to perform network operations on a thread other than the main UI thread; a NetworkOnMainThreadException is thrown otherwise.

In order to address this issue we recommend you to:

  1. See: https://developer.android.com/training/basics/network-ops/connecting
  2. Consider alternative libraries (e.g., Retrofit) handling asynchronous operations

Potential Code Location with synchronous operations:

final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

@amazuerar amazuerar changed the title Synchronous operations are being implemented Avoid synchronous operations implementation Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant