How to pass an HttpClient instance to another activity ?

by Chavepeyer Geoffrey » Tue, 24 Feb 2009 01:34:01 GMT


Sponsored Links
 Hi everybody !

I'm really new on Android so it may be a stupid question :)

I'd like to know how I can pass the instance of HttpClient created in
a first activity to a second activity.

What I'm trying to do is to connect to a webservice that uses sessions
to handle the identification. Therefore I need to always use the same
instance of HttpClient so that the sessions is kept alive.

Here is how I want to do this :

I start my first activity displaying an login and password form. When
clicking on the connection button, the activity logs the user on the
webservice by doing a POST. The webservice answer with a login status
and if the user is valid, I forward the user to another activity that
have touse the same session for requesting data to the webservice in
order to keep the same session.

Thanks a lot for everyone's help !

Geoffrey

--~--~---------~--~----~------------~-------~--~----~



How to pass an HttpClient instance to another activity ?

by Mark Murphy » Tue, 24 Feb 2009 02:05:17 GMT


 


Assuming you really want to do that, you can have the HttpClient be a
public static data member of one of the activities (or some common
utility class) and reference it from any activity that needs it.


Technically, you only need to share an instance of the CookieStore,
which is where your session cookies would reside. However, it may be
simpler just to share the whole HttpClient as you suggest.

Note that if you are going to be accessing the HttpClient from threads
other than the UI thread -- which is a really good idea -- be sure to
set up the HttpClient for multithreaded use, as demonstrated here:

 http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientMultiThreadedExecution.java 

(or  http://tinyurl.com/dhu9up if that URL is too long )

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android Training in Sweden --  http://www.sotrium.com/training.php 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


How to pass an HttpClient instance to another activity ?

by Chavepeyer Geoffrey » Tue, 24 Feb 2009 16:30:05 GMT


 Thanks a lot !

It solved my problem :)
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. ListView sometimes not calling onScrollStateChanged() when stop scrolling

Normally this works fine - when scrolling stops, onScrollStateChanged() is 
called with SCROLL_STATE_IDLE.

However, sometimes it just isn't called. This can be observed from one touch 
to the next (i.e. it's not an implementation detail).

This is a problem, because I use the scroll state to determine when to 
pause/resume intensive background thread work.

Anyone got a workaround?

-- 

2. select a row in a listview

Hi,
I'm newbie on android dev. Sorry for any problem....I have a listview wich i
display 3 columns (id,restaurant,city) from a sqlite...(using a
simplecursoradapter to bind)how I select a row and open it to edit or view.

Anyone has a reference to send me or example !?

Thanks 
Igor

-----Original Message-----
From: android-developers@googlegroups.com
[mailto:android-developers@googlegroups.com] On Behalf Of ehpaul
Sent: sexta-feira, 25 de maro de 2011 15:15
To: Android Developers
Subject: [android-developers] Re: Any way to detect if the GPS data is
"real"

Thanks for your reply. Sorry that I didn't post my question clearly.
As I am aware, it possible for my 3rd party app to manipulate the GPS
location. My question is that if there is any way to detect the location is
"Real" from the satellite instead of manipulated?






--


-- 

3. Lucky Sebastian @UPN Jakarta

4. onPause() Why u no do the things I want?

5. [WTI] Google delays open access to new Android software

6. collision detection

7. Virus yang menyerang gmail.