It seams like to work with chat application, using openfire and smack there can be two ways below,
First Way
Smack makes a connection with the openfire server and it can receive and send updates to the server as long as its connected to the openfire server. In case its not connected, theres a plugin on openfire which keeps the messages offline, and send them once the client is connected again. In this scenario to receive all messages,
- 1.1 Device should only disconnected from the openfire in case if it don’t have internet.
- 1.2 User is sign out
- 1.3 Device is offline
If connection goes disconnected with the server in any other case this cause messages loss. Currently application is working with this architecture.
Problems with this method:
- The major problem for this is if due to any crash, or problem application gets completely killed, and its not alarm manager task also gets killed. App didn’t restart until the application opens again.
- Second problem with this is, its consuming battery due to continuous process
- On updated OS application goes in deep sleep, doze mode, ulta power save mode, background
Second Way
2.Smack makes a connection with the openfire server and it can receive and send updates to the server as long as its connected to the openfire server until the application is in foreground. As soon as this goes in background the application will completely disconnect from the server. In this case as application is offline openfire have to send all the messages to the Firebase server, same application listens for the firebase notifications and when it receives the notification from firebase it reconnects to the openfire and gets the message and display or shows the message directly from firebase (in this case this record goes to the firebase server as well). Application receives that notification from the gcm and then need to manage in application about message delivery etc.
Problems
- Disconnect from server when app goes in backgound, handle its usecases as app is in background for long time or not. Is app goes in background to select any file and use cases like this.
- This makes the code and application very compelex and need to manage multiple servers as well.
- There can also be more security breaches as i don't want to share my application messages data with any third party.
My Questions
- Which way is better, secure and more reliable to use?
- My application is working with way 1, should i switch to second way ?
- what can be possible reasons to make sure that app stays connected in each and every way? and it consumes less batter as well?