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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:14:20+00:00 2026-06-09T06:14:20+00:00

In my application i am using a PHP web server. In the main activity,

  • 0

In my application i am using a PHP web server.

In the main activity, i make a connection to the server using Username and Password.
Taking these values, the server starts my session.

So to maintain the session i use the same HTTP Client through out the Application.

public static HttpClient httpclient = new DefaultHttpClient();

But the problem is, most of the time if i want to fetch data from the server i use background threads to get data and then update the UI thread. So when the client i allocated in the background and user tries to make someother connection by clicking on a Button on the UI. It gives me this Exception

Invalid use of SingleClientConnManager: connection still allocated.

I am catching this Exception, so the application wont crash, but the session is getting destroyed. And hence i end up showing ‘Null’ in some View.

Can anyone please help me how to maintain sessions in a better way and how to avoid this SingleClientConnManager Exception.

Thank You

I thought of this approach:

when the application crashes or gives a singleClientConnManager exception (in either cases the session is lost) using java.lang.Thread.UncaughtExceptionHandler i make a connection to the server again, using the username and password stored using Shared Preferences (this will start the session again) and then restart the current Activity. I did’t try this, but i want to know is it a good practice?

  • 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-09T06:14:21+00:00Added an answer on June 9, 2026 at 6:14 am

    You should try and avoid that exception, not catch it and work around it! The suggested approach does NOT look like good practice to me.

    The problem seems to me that you have only a single connection, but the user can start 2. If that is the case, you should be able to handle it, or stop the user from doing so.

    • One option would be: recognize that you already have a connection (do not rely on the exception for this), and then start a new one. What I mean is that in this case you don’t rely on the connection throwing an exception, but you check if there is allready one by ‘normal’ means (some variable for instance). You can go from there with what sounds like a bit of a hack (restarting the activity and all), but it is better then waiting for an exception.

    • Another option might be is stopping the user from pressing the button while the other request is still going on, but depending on your application that might be a user-interface fail. That depends on what the user sees and what’s going on I guess. You can do this by using a spinner, disabling the buttons in all but form, there are nummerous ways to accomplish this.

    • Lastly, you might want to ‘queue’ the request and only send it to the server once the precious request is done. This way you can use the connection without exceptions. What I mean is that you keep everything as it is, but the action after pressing the second button is to remember you have to do the action, and after the first action returns, then check if there is anything else to do.

    Do not rely on exceptions for the flow of your code!

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

Sidebar

Related Questions

I need to develop a web application using PHP and the Apache web server.
I'm using lighttpd as webserver for php application server. The avg. load on this
I am developing an web application using php. One of the requirement is the
I'm currently designing a web application using php, javascript, and MySQL. I'm considering two
I need to create a web application using php, I had many users having
I am creating a login system for a web application using PHP. My question
A legacy web application written using PHP and utilizing MySql database needs to be
I did a small web application for using PHP, HTML, and JavaScript. I want
All, I have a PHP Web application built using Zend Framework and MVC with
When using Eclipse PDT with XDebug to debug a PHP web application, is there

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.