I'm developing an app with chat as a mini feature. I've two chat screens one for conversations listing lets call it ActivityA and other for actual message sending and reading lets call it ActivityB. The problem is that my chat server can only handle a limited number of concurrent open connections. So, to optimise connections, I'm trying to only connect when user is at any of chat screens and disconnect as soon as the chat screens go away i.e. stoped. For this, I tried using Activity's lifecycle methods onStart and onStop. I connect on onStart and disconnect on onStop. The problem is that the onStop ActivityA is called after onStart of ActivityB. Hence when user lands on ActivityB the connection get dismissed and no message can be sent. How can I fix this issue, please help?