-
-
Save DeepakRattan/b9cbcdc5c12eb6e12af0 to your computer and use it in GitHub Desktop.
How to send Socket object from the service to the activity which starts it?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SocketService extends Service { | |
@Nullable | |
@Override | |
public IBinder onBind(Intent intent) { | |
return null; | |
} | |
@Override | |
public int onStartCommand(Intent intent, int flags, int startId) { | |
return super.onStartCommand(intent, flags, startId); | |
} | |
@Override | |
public void onCreate() { | |
Log.e("Service", "created"); | |
try { | |
Socket mSocket = IO.socket(Constants.CHAT_SERVER_URL); | |
Log.e("ValueSocket", String.valueOf(mSocket)); | |
//I want to send mSockets to the activity which will start the Service | |
} catch (URISyntaxException e) { | |
e.printStackTrace(); | |
} | |
super.onCreate(); | |
} | |
// Event Listeners | |
private Emitter.Listener onConnect = new Emitter.Listener() { | |
@Override | |
public void call(Object... args) { | |
Log.e("Socket", "Connected"); | |
} | |
}; | |
private Emitter.Listener onConnectionError = new Emitter.Listener() { | |
@Override | |
public void call(Object... args) { | |
Log.e("Error", "Error in connecting server"); | |
} | |
}; | |
private Emitter.Listener onDisconnect = new Emitter.Listener() { | |
@Override | |
public void call(Object... args) { | |
Log.e("Disconnect", "Socket Disconnected"); | |
} | |
}; | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment