Hello, I have the link below
link
handing me a string %code% % type
%pre%
So, in %code% , handle it with% %code% below:
%pre%
This %code% % works normally. However, you need to put the code snippet below;
%pre%
Otherwise, the connection to the internet is NOT established.
However, I've added the INTERNET access permission on the %code% .
%pre%
But no use.
If I remove this block of code
%pre%
The connection to %code% does not.
The problem is that if I work that way, as often as the ones I need to access the %code% % is the same number of times you have to make use of this code snippet.
Is not there a general configuration file for this in %code% %?
Following the %code% % JsonClass
%pre%
______ azszpr352394 ___
What happens is that your %code% tries to access the network (a blocking operation) in the main Android thread, which is not allowed.
You can read more about this , but to summarize: A The main Android thread is responsible for updating the views.
Doing blocking tasks such as accessing the network or the database in this thread causes the view to crash, giving that impression of lag in the application.
The above link also gives you an alternative to solve this problem: do this type of tasks within AsyncTasks .
I particularly prefer to delegate all this work to libraries like Retrofit .
Doing what you want with this lib is very trivial:
After adding dependencies , define the contract on an interface:
%pre%
Starts the service instance:
%pre%
And to consume the service in a non-blocking way, just call:
%pre%
Now, within the callback %code% you already have the webservice response parseada and ready to use.
___