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. signatures permissions and what else is missing in sdk documensts.

I am new to Android.

A WAP PUSH receivers defines permissions & I've seen in some cases,
they uses signatures in manifest files.
Q: Can a intent-filter use any string as a mime type or the mime types
must be pre-register(Accepted) somewhere in system?

Q: What about the permissions? Who is really granting these
permissions?
e.g.:

 <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
<intent-filter>
  <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" /
  <data android:mimeType="application/vnd.oma.drm.rights+xml" />
</intent-filter>

Reason I am asking:
My WAP Push receiver doesn't receive any wap push sent to the device.
I do everything exactly as examples and now I have a reason to believe
that there are some "important details" missing in android sdk
documentations.

I would really appreciate to get some help/info ASAP!!!
Thanks

-- 

2. Which emulator to use to better simulate a Nexus One

Hi,

I have an application that I have tested with high definition devices
on the adb but the real users of Nexus one are seeing some display
problem that I can't simulate

What is the configuation to use to simulate a nexus one (SDK, device,
etc..)

Thanks

Nicolas

--

3. Working with the new ContactContracts API

4. Network Unreachable (Socket.net Exception)

5. DHCP Address on WiFi

6. Pintu Air Bogor Jebol! Jakarta Siaga 1 Banjir

7. How to overlay POIs on Camera