我正在使用Chat messenger。我使用了socket.io-client库。我已经创建了一个实例化Socket类的服务。
SocketService.java
public class SocketService extends Service {
public static Socket mSocket;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
String data = intent.getStringExtra("Socket");
Log.e("intent data", data);
Log.e("Service", "Called");
}
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onCreate() {
super.onCreate();
Log.e("Service", "created");
try {
mSocket = IO.socket(Constants.CHAT_SERVER_URL);
Log.e("ValueSocket", String.valueOf(mSocket));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
我在SplashActivity.java中启动服务。我必须将Socket实例即mSocket传递给Activity SplashActivity.java。如何才能在android中实现这一点?请帮忙。