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. VERY URGENT : The app not working fine on 1.5G emulator (target name: Google APIs) which is working fine on 1.0 emulator

Hi I have written a location based app.

The app finds a route between two coordinates. Its working fine on 1.0
emulator as well as on 1.0 supported devices.

Now I tried to run the same app on 1.5G (Google APIs ) emulator. Its
not working. It is not showing the route. and got the following log
messages:

D/GpsLocationProvider(  568): setMinTime 0
I/Maps.MyLocationOverlay(  655): Request updates from gps
E/LocationManagerService(  568): isProviderEnabled got exception:
E/LocationManagerService(  568): java.lang.IllegalArgumentException:
provider=network
E/LocationManagerService(  568):        at
com.android.server.LocationManagerService._isProviderEnabledLocked
(LocationManagerService.java:1514)
E/LocationManagerService(  568):        at
com.android.server.LocationManagerService.isProviderEnabled
(LocationManagerService.java:1499)
E/LocationManagerService(  568):        at android.location.ILocationManager
$Stub.onTransact(ILocationManager.java:245)
E/LocationManagerService(  568):        at android.os.Binder.execTransact
(Binder.java:287)
E/LocationManagerService(  568):        at dalvik.system.NativeStart.run
(Native Method)


and I tested the maps app on 1.5G emulator. When I tried to get my
current location,
I got the alert "Your location cannot be determined. We will keep
trying, but you can also try moving your position".

and the log says:
D/GpsLocationProvider(  568): setMinTime 0
I/Maps.MyLocationOverlay(  655): Request updates from gps
E/LocationManagerService(  568): isProviderEnabled got exception:
E/LocationManagerService(  568): java.lang.IllegalArgumentException:
provider=network
E/LocationManagerService(  568):        at
com.android.server.LocationManagerService._isProviderEnabledLocked
(LocationManagerService.java:1514)
E/LocationManagerService(  568):        at
com.android.server.LocationManagerService.isProviderEnabled
(LocationManagerService.java:1499)
E/LocationManagerService(  568):        at android.location.ILocationManager
$Stub.onTransact(ILocationManager.java:245)
E/LocationManagerService(  568):        at android.os.Binder.execTransact
(Binder.java:287)
E/LocationManagerService(  568):        at
com.android.server.SystemServer.init1(Native Method)
E/LocationManagerService(  568):        at
com.android.server.SystemServer.main(SystemServer.java:412)
E/LocationManagerService(  568):        at
java.lang.reflect.Method.invokeNative(Native Method)
E/LocationManagerService(  568):        at java.lang.reflect.Method.invoke
(Method.java:521)
E/LocationManagerService(  568):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/LocationManagerService(  568):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
E/LocationManagerService(  568):        at dalvik.system.NativeStart.main
(Native Method)
W/I


I am not understanding why I am not getting the current location.

Can any one please help me to solve this problem?

Thanks,
Manoj.
--~--~---------~--~----~------------~-------~--~----~

2. how to get focus window in inputmethod's view

I add a fullscreen view which has no focus flag, in inputmethod for
chinese handwrite.

now, I want to get the focus window under my fullscreen view when I
touch screen.

thanks
--~--~---------~--~----~------------~-------~--~----~

3. Procedure to send dbus messages through command line

4. How to redirect audio to bluetooth headset?

5. Is there any doc exist for porting android 1.5 into x86

6. Emulator is not coming up if we will do the changes in CUPCAKE version

7. Is there any guides for porting android into x86?