How to make my app to keep connection on Socket server and to run on foreground and background. I need to receive some notification and data from Server. Until now my app work only when is open, and when i close or only back the connection stops.
And When app is closed and user run app again and try to connect to server again connection don't happen, then I need to restart the server and connect again.
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
iSocketInterface = ISocketInterface.Stub.asInterface(iBinder);
socketServiceBound = true;
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
iSocketInterface = null;
socketServiceBound = false;
}
};
@Override
protected void onStart() {
super.onStart();
// Bind to LocalService
Intent intent = new Intent(this, SocketService.class);
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
protected void onRestart(){
super.onRestart();
}
protected void onResume(){
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onStop() {
super.onStop();
}