0

I'm working on a simple multiplayer game on android. I have NetworkManager class which opens connection to the server and provides methods like send and receive.

public class NetworkManager { private Socket socket; public NetworkManager() throws IOException { socket = new Socket(HOST, PORT); ... } public void send(String msg) throws IOException { ... } } 

In one activity I connect to the server by creating new instance of NetworkManager. Then, I have to use that instance in several other activities. Is it possible to pass reference to it when starting new activity?

1

1 Answer 1

1

No, and you should not do it anyway. Use a service to do the background work: https://developer.android.com/guide/components/services.html - or at least an AsyncTask, but for your use case a service should be a better option.

You can only pass primitive or Parcelable types from one Activity to another.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.