From the main activity of an android application, is it possible pass a Socket type parameter to a service upon starting the service?
Asked
Active
Viewed 68 times
1 Answers
0
There are some ways to do that:
Use global variable to store your socket instance, then in your service, just call it
public class MyApplication extends Application { private static Socket socket; public Socket getSocket() { return socket; } public void setSomeVariable(Socket otherSocket) { this.socket = otherSocket; } }
Use intent to pass and receive data field by field (or can use serializable or Parcelable). But this way will create other instance of socket
Use event bus to send and receive from activity to service
-
How would you call it in the service? – user3705359 Jun 04 '14 at 17:39