Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:37:41+00:00 2026-06-09T01:37:41+00:00

So… I’m making an application for Android. The application needs to send and receive

  • 0

So… I’m making an application for Android. The application needs to send and receive realtime chat data (needs to be a socket) but it also needs to send commands (which don’t as the client knows when it is sending something).

I need to know what is a better solution in terms of saving the user’s battery.

a) Opening and Closing the connection every time a command is sent, if the chat tab is opened then keep the connection constant.

b) Keep the connection constant all the time.

I’ve taken a look around the internet but have gotten mixed answers, some say keeping a persistent connection is bad for battery life and others say that it isn’t (Example: “Are you asking if holding a TCP connection open will drain battery-life? Maybe I am WAY off here but, holding a connection open shouldn’t waste battery life… If you think it will I would love to know where you got that information. It sounds SO strange to me.”)

Or if there is another solution that would be better. I don’t think that Google’s C2DM would be very useful at all in this situation either.

Basically, what drains the battery more: having a persistent connection, or opening and closing the connection unless the chat tab is open?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:37:43+00:00Added an answer on June 9, 2026 at 1:37 am

    Keeping an idle TCP socket connection open (with no data being sent or received) will not (or at least, should not) consume any more battery than having it closed. That is because an idle TCP connection uses no bandwidth or CPU cycles(*).

    That said, keeping a TCP connection open for extended periods may not be a good option for a mobile device, because TCP connections don’t interact well with computers that go to sleep. The problem scenario would be this: your Android user puts his Android device to sleep while your app is running, and then the remote user’s program (or whatever is at the other end of the TCP connection) sends some data over the TCP stream. The remote user’s program never gets any ACKs back from the Android device, because of course the Android device is asleep, so the remote device’s TCP stack assumes that the TCP packets it sent must have been lost, and it responds by increasing its timeout period, decreasing its TCP window size (aka number-of-TCP-packets-allowed-in-flight-at-once), and resending the TCP packets. But the Android device is still asleep, and thus the same thing happens again. The upshot is that a few minutes later, the remote end of the TCP connection has slowed down to the point where even if the Android device was to wake up, the TCP connection will likely be too slow to be usable — at which point your program will need to close the bogged-down TCP connection and start up a fresh one anyway, so why bother trying to keep it open?

    So my recommendation would be to go with option (a), with the stipulation that you close the TCP connection as part of your device-is-going-to-sleep-now routine.

    One possible caveat would be if Android has a feature where keeping a TCP connection open causes the WiFi or cell-network hardware to remain powered up in a situation where it could otherwise be put to sleep — if that is the case, then the Android device would pay a battery cost for powering the antenna, which it wouldn’t otherwise have had to pay. I’m not aware of any Android logic like that, but I’ve only used Android a little so that might just be ignorance on my part. It might be worth testing for, at least.

    (*) Well, technically TCP does send a “keepalive” packet every so often while a TCP connection is open, and that does use some CPU cycles and antenna power… but the default interval for sending keepalive packets on Android is two hours, so I doubt the power used for that would be noticeable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've successfully connected to XMPP server (from android XMPP client), and I can send
Why does the Android system throw this Exception? 05-18 12:33:44.169 W/System.err( 8230): java.io.IOException: Is
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('…')
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I have been making a wordpress template. i got stuck at some place... the
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
See below matrix data: A B C D E F G 1 89 92
what about this one: I want to format the currentTime displayed by a videoPlayer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.