I have a small chat application. When it starts it binds to a service. This service has a tcp/ip connection with the server.
When the application is not in foreground my service creates a status notification. So far so good.
When the application is destroyed for example using task manager on "onDestroy" method I call unbind. Now the service is killed. So my question is how I make a service to stay alive even there is no clients bind with it.
Googe doc: " The service will remain running as long as the connection is established (whether or not the client retains a reference on the service's IBinder)."
Thanl you.
What Does Keepalive Mean? A keepalive is a signal sent from one device to another to maintain a connection between the two devices. This may be between a client and a server, but it could apply to any number of devices or technologies.
Foreground services perform operations that are noticeable to the user. Foreground services show a status bar notification, so that users are actively aware that your app is performing a task in the foreground and is consuming system resources.
You can make your service a foreground service, which will display an icon in the notification bar so that the user can see your service is running. Otherwise, you cannot keep your service running. By the way, you should be aware that an everlasting service is an Android antipattern, the system should be able to kill off your app when memory is low, and apps haven't used it in a while. If you are doing something that legitimately needs to live "forever" you should do so with a foreground service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With