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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:01:43+00:00 2026-05-25T10:01:43+00:00

I can find loads of tutorials that show how should a HttpClient constructed and

  • 0

I can find loads of tutorials that show how should a HttpClient constructed and used in a simple case. But I fail to find any decent documentation for more complex cases.

In my app, I have a bunch of Activities, and each has to be able to communicate with a remote WebService with POST messages using HTTPS. I also have to log in to this service, so I need to manage the login cookie.

Currently, I construct a separate HttpClient for every single Activity in .onStart(), and releasing it in .onStop(). I have a work-queue that contains the objects describing the details of a task that has to communicate with the remote service. I execute these tasks using a single worker AsyncTask. This solution seems to work, but I’m just not sure that it’s the most optimal one.

I’ve thought about 2 other architectures:

  1. Creating a background Service that handles the HttpClient. This way I might be able to use the same instance thru multiple Activities, and I guess this’d be better. But I’m not sure when to stop this Service and release the HttpClient.
  2. Create a HttpClient only when needed. So for example when the user clicks a button that initiates a remote call, then I construct the client, set up the cookies and the POST message, execute it, and when it’s done I immediately release it. I think this approach is quite bad because of the overhead involved in creating such a client (especially if I use HTTPS).

So anybody that has more insight about the workings of HttpClient and how it should be treated in Android, could you please comment on these approches / share some useful tips?

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-05-25T10:01:44+00:00Added an answer on May 25, 2026 at 10:01 am

    solution 1 is good. You can stop your service once your queue is empty. It combines with your solution 2 in that that the service is started only when needed. When your user clicks a button, you start your service, and for instance you bind to it and give it your request.

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

Sidebar

Related Questions

I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing
Are there any tutorials that can teach me how to use mipmapping in my
I've read a lot of Zend controller testing tutorials but I can't find one
I know this should be easy to find via google, but I can't seem
I need to find/create a library that can load hdr images in many formats
I can find the definition files at http://www.php.net/~helly/php/ext/spl/... but I want to extend DirectoryIterator
I read the Java tutorials on Sun for JAR files, but I still can't
std::atomic is new feature introduced by c++11 but I can't find much tutorial on
Using some tutorials I wrote simple widget but it causes error declare customwidget.TestDijit: mixin
I'm using Spring Security 3.0.2 and I can't find a way to load roles

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.