title: How to make my android app method less RAM consuming
body: <p>I was looking for some advice on making my application more RAM friendly. On a larger android tablet device the app works fine and I'm testing on a HTC Desire S running Android 2.3.5 which I know is an ANCIENT phone by today's standards but whenever I try to run this method the phone will FORCE CLOSE. I was wondering if there was any advice people could provide with modifying my code to make it a bit more efficient in terms of RAM.</p>
  
  <p>Please see below my android method and my logcat printout: </p>
  
  <p><strong>Android activity method</strong></p>
  
  <pre><code>public void uploadDataToCrowdSnapCymru() throws UnsupportedEncodingException {
      ArrayList&lt;NameValuePair&gt; nameValuePair = new ArrayList&lt;NameValuePair&gt;();
      nameValuePair.add(new BasicNameValuePair("name", nameString));
      nameValuePair.add(new BasicNameValuePair("desc", descString));
      nameValuePair.add(new BasicNameValuePair("lat", latString));
      nameValuePair.add(new BasicNameValuePair("lng", lngString));
      nameValuePair.add(new BasicNameValuePair("project", projectString));
  
      ByteArrayOutputStream bao = new ByteArrayOutputStream();
      photo.compress(Bitmap.CompressFormat.JPEG, 100, bao);
      byte [] ba = bao.toByteArray();
      String ba1=Base64.encodeBytes(ba);
      nameValuePair.add(new BasicNameValuePair("snap", ba1));
  
      try {
          //EXECUTE POST
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://users.aber.ac.uk/dwd/mfb/php/receiveUserData.php");
          httppost.setHeader("Content-Type",
                  "application/x-www-form-urlencoded;");
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePair, "UTF-8"));
          HttpResponse response = httpclient.execute(httppost);
          String responseText = EntityUtils.toString(response.getEntity());
          System.out.println(responseText);
  
          if(responseText != null){
              Toast.makeText(this, "Record uploaded! View it at CrowdSnapCymru.com", Toast.LENGTH_LONG).show();
          }
      }
  
      catch(Exception e) {
          Log.e("log_tag", "Error in http connection"+e.toString());
  
      }
  }
  </code></pre>
  
  <p><strong>LogCat printout</strong></p>
  
  <pre><code>05-15 23:52:55.938: E/dalvikvm(8950): Out of memory: Heap Size=9927KB, Allocated=5369KB, Bitmap Size=8756KB, Limit=20480KB
  05-15 23:52:55.938: E/dalvikvm(8950): Extra info: Footprint=9927KB, Allowed Footprint=9927KB, Trimmed=504KB
  05-15 23:52:55.938: D/AndroidRuntime(8950): Shutting down VM
  05-15 23:52:55.938: W/dalvikvm(8950): threadid=1: thread exiting with uncaught exception (group=0x400205a0)
  05-15 23:52:55.938: E/AndroidRuntime(8950): FATAL EXCEPTION: main
  05-15 23:52:55.938: E/AndroidRuntime(8950): java.lang.OutOfMemoryError: (Heap Size=9927KB, Allocated=5369KB, Bitmap Size=8756KB)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:122) 
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at rcahmw.prototype.crowdsnapcymru.UploadRecord.uploadDataToCrowdSnapCymru(UploadRecord.java:119)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at rcahmw.prototype.crowdsnapcymru.UploadRecord$1.onClick(UploadRecord.java:85)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at android.view.View.performClick(View.java:2532)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at android.view.View$PerformClick.run(View.java:9293)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at android.os.Handler.handleCallback(Handler.java:587)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at android.os.Handler.dispatchMessage(Handler.java:92)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at android.os.Looper.loop(Looper.java:150)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at android.app.ActivityThread.main(ActivityThread.java:4277)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at java.lang.reflect.Method.invoke(Method.java:507)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  05-15 23:52:55.938: E/AndroidRuntime(8950):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  </code></pre>
  
  <p>Any advice anyone could provide would be well received. ALSO a final question will <code>HTTP POST</code> methods work on a mobile network as well as Wi-Fi? Thanks. I'm assuming they do as internet browsers apps work on both network and wifi and its kind of the same principal.</p>