HTTPPost/Get: Running simultaneous android apps

Put your problem here if it does not fit any of the other categories.

HTTPPost/Get: Running simultaneous android apps

Postby android_newbie2009 » Fri Nov 13, 2009 2:38 pm

Hi,

I have two separate applications that run simultaneously. One is meant to post location coordinates to a SQL database as soon as the person's location changes. It accesses a php file which updates the database. The second application accesses the same php file and it also implements locationlistener. It looks like I may be receiving an ANR for one application as I open the other application though I never see an ANR window. I do see that the location coordinates are not posted to the database so I know there's something wrong.

I've read where there's a difference in the HTTPClient execute (one is syncrhonous and the other asynchronous). I switched to the asynchronous call (the same call is implemented in both apps - see code below) Can anyone tell me why this is failing? IE, why won't both apps run simultaneously? I noticed with the synchronous call, it works for about 5 minutes or so but then one app fails. It seems as though with the asynchronous call, the fail happens immediately.

String queryString = "http://linkto.php/plusparams
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(queryString);

// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);


// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
android_newbie2009
Freshman
Freshman
 
Posts: 4
Joined: Fri Nov 13, 2009 1:51 pm

Top

Postby padde » Fri Nov 13, 2009 7:11 pm

Just implement a Service.. this will save you a lot of trouble.

I will try to exemplify with my mad ascii art skills :lol:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                         set      __________                      _______________
  3.  
  4.                     |---------->|          |     Connects       |               |
  5.  
  6.                     |           | Service  |------------------->| PHP on Server |
  7.  
  8.                 ____|_______    |__________|                    |_______________|
  9.  
  10.                |            |         |           ____________
  11.  
  12.                | Activity 1 |         |    get   |            |
  13.  
  14.                |____________|         |--------->| Activity 2 |
  15.  
  16.                                                  |____________|
  17.  
  18.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 10 guests