Issue maintaining persistent connection

I have an android app which connects to OpenFire server. If the app is closed (swiped out), the messages stop delivering to the app client. How can I fix this?

Also, even in normal working state, sometimes the client goes offline, probably because there was a short internet disconnection.