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 8385961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:47:55+00:00 2026-06-09T17:47:55+00:00

I am building an Android App that will communicate over TCP with a server.

  • 0

I am building an Android App that will communicate over TCP with a server. I have a few ideas for implementation and I don’t know which way would be best to go. I am new at this and my design is constantly evolving as I learn new things, so now I am looking for advice for how to best implement a solution to fulfill my goal.

Goal: Be able to:

  1. send data to a server
  2. Send data to a server and read the servers response.

    • Some information I send will be to give the server information, other will be to request information from the server.

Possible implementations:

  • Thread Run() method constantly loops through checking if my send queue has something to send (and sending it if it does) then checking if I have anything to read back in.
    • Will this drain battery/burn CPU?
  • Create a new thread each time I want to send/receive, the let it die once I have done ‘send’ or ‘send + receive’
    • How should I synchronize the threads interactions with my one socket? Block making the next thread until this one finishes?
  • Make a thread and call a send or send + receive method withing that thread each time I need to write or write + read
    • How do I keep the thread alive without burning battery/CPU?
    • should I use a queue to handle requests for transmitting data and should I synchronize reading from it until the current read/write is finished?

Any additional pointers, links, or warnings about potential issues would be much appreciated. Sample code is especially appreciate as I am just starting out with this. Thank you.

  • 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-09T17:47:56+00:00Added an answer on June 9, 2026 at 5:47 pm

    As you’ve pointed there are several ways of achieving this, each of them has its advantages and weaknesses.

    Leaving a connection open, or re-sending them very often will definitely make a difference in battery duration. If this is your case I’d think about batching some requests into one every certain amount of time. Here is a interesting article about that.

    I wrote some days ago about an approach I’m using very often which works pretty nicely. It can be as simple as it looks or set the basis for a whole API communication engine for your Android app. It is up to your needs. It is basically executing your requests in a pool of background threads, controlled by a service and notified within your activities or whatever you need.
    Whenever you need to push a new requests it as simple as enqueueing it and setting the callback.
    If you think that might work for you here I leave you a pair of links diving deeper into this.

    http://ugiagonzalez.com/2012/07/02/theres-life-after-asynctasks-in-android/
    http://ugiagonzalez.com/2012/08/03/using-runnables-queues-and-executors-to-perform-tasks-in-background-threads-in-android/

    Hope it helps.

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

Sidebar

Related Questions

I've started building an android app that will connect to a sql server and
I'm building my first android app - something that will display my tweets in
I am building an Android app that uses wifi. I have properly declared these
I'm building an Android app that will stream several radio stations from a Latin
I am building an app that will be bundled on an android device as
I'm building a web app using jquery mobile that will have lots of images
I am building an Android application that will send reports to a server. These
I am building an android app, and I want to be able to have
I am building an Android app using phoneGap and I have successfully added the
I'm building an Android app and I need to have two different themes for

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.