Answer the question
In order to leave comments, you need to log in
How to interact with socket in android?
Good day. I am developing an android application that will communicate with the server via sockets. And the question arose: how to properly store the socket object? Does it need to be recreated on every request, or only opened when the application starts? Then how to access it from anywhere in the application? Through a singleton? But then how to do it with parameters? There are more questions than answers. Maybe someone faced this in their applications?
Answer the question
In order to leave comments, you need to log in
You can use a Service that will create an instance of the socket class and work in the background, and you can get a service from other classes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question