Login Retains Session on Emulator But Not on My Driod

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Login Retains Session on Emulator But Not on My Driod

Postby q42blaster » Wed Sep 29, 2010 7:28 pm

I am using org.apache.http and the following code:


Snippits from WebHelper Class...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public List<Cookie> get() throws ClientProtocolException, IOException {
  3.                 httpget = new HttpGet(URL);
  4.                 response = httpclient.execute(httpget);
  5.                 entity = response.getEntity();
  6.                 if (entity != null) {
  7.             entity.consumeContent();
  8.         }
  9.                 return cookies = httpclient.getCookieStore().getCookies();
  10.         }
  11.  
  12.         public List<Cookie> post(List<NameValuePair> postData) throws ClientProtocolException, IOException {
  13.                 httppost = new HttpPost(URL);
  14.                 nameValuePairs = postData;
  15.                 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
  16.                 httppost.getParams().setBooleanParameter( "http.protocol.expect-continue", false );
  17.                 response = httpclient.execute(httppost);
  18.                 entity = response.getEntity();
  19.         if (entity != null) {
  20.             entity.consumeContent();
  21.         }
  22.         return cookies = httpclient.getCookieStore().getCookies();
  23.         }
  24.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Snippits from my Activity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 web.setURL("http://mydomain.com/login");
  2.                 web.get();
  3.                 List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  4.                 nvps.add(new BasicNameValuePair("username", user.get(0).toString()));
  5.                 nvps.add(new BasicNameValuePair("password", user.get(1).toString()));
  6.                 List<Cookie> returnData = web.post(nvps);
  7.                 String successCookie = returnData.get(0).getName().toString();
  8.                 if (successCookie.equals("USERNAME")) {
  9.                      //Store User/Pass in DB
  10.                 }
  11.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


The weird thing is I am seeing the correct data on my emulator, but when I switch it over to my phone I do not get that data.

It is able to log in and I am able to see the cookies when I debug it on my phone, but I do not get logged in content. So it's behaving as if I am not logged in.

I am using the this permission:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Is there something I am missing?

Thank you,

Andrew
q42blaster
Freshman
Freshman
 
Posts: 3
Joined: Wed Sep 29, 2010 7:16 pm

Top

Re: Login Retains Session on Emulator But Not on My Driod

Postby q42blaster » Wed Sep 29, 2010 9:07 pm

I forgot to mention I am using 1.6 on the emulator to test and I have 2.2 on my phone. I did some research and saw someone said to use entity.consumeContent();

But when I do this (the second time after authentication) it seems to completely wreck everything.
q42blaster
Freshman
Freshman
 
Posts: 3
Joined: Wed Sep 29, 2010 7:16 pm

Re: Login Retains Session on Emulator But Not on My Driod

Postby q42blaster » Wed Sep 29, 2010 9:21 pm

I just now tested it on my 2.2 emulator and I do get logged in content. I uninstalled the app from my phone and cleared the data, but still not getting logged in data. I'm not sure what's different between the emulator and the actual device.
q42blaster
Freshman
Freshman
 
Posts: 3
Joined: Wed Sep 29, 2010 7:16 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: Google [Bot] and 4 guests