As the title suggests, I am trying to create a singleton class for maintaining a TCP socket across different activities in my application. I am almost an absolute beginer to this and would really appreciate someone pointing me in the right direction.
UPDATE:
Here is the code for the class that I wrote:
public static ConnectionManager getInstance() {
if(instance == null) {
instance = new ConnectionManager();
}
return instance;
}
public void send(String str){
try{
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(access_point.getOutputStream())),true);
out.println(str);
}
catch(IOException e){
e.printStackTrace();
}
}
}
AND HERE IS HOW I CALLED IT ON ONE OF THE ACTIVITIES
private static ConnectionManager command = ConnectionManager.getInstance();
.........
command.send("Turn on");