title: How to use the Parcelable class properly in Android
body: <p>I have a class (below) that I want to send to a Service Class through an Intent.  I have implemented the Parcelable interface but am unsure how to actually send and retrieve the entire object including the current state of the object.</p>
  
  <p>In particular     </p>
  
  <pre><code>@Override 
  public void writeToParcel(Parcel dest, int flags) {
        //I need this to send the entire state of the object
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>public UrlParamsHelper(Parcel in) {
      //I need this to unpack the state of the object
  }
  </code></pre>
  
  <p>Here is the actual class</p>
  
  <pre><code>/*
    * A holder class for URL parameters
    */
   public static class UrlParamsHelper implements Parcelable {
    private final HttpClient httpClient;
    private final HttpParams params = new BasicHttpParams();
    private final SchemeRegistry registry = new SchemeRegistry();
    private final ThreadSafeClientConnManager manager;
    private final Uri.Builder uri = new Uri.Builder();
    final HttpHost host;
  
    final String urlPath;
    final String hostname;
    /*
     * @param hostname the hostname ie. http://www.google.com
     * @param urlPath the path to the file of interest ie. /getfiles.php
     */
    public  UrlParamsHelper(final String hostname, final String urlPath) {
     HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
     HttpProtocolParams.setContentCharset(params, "UTF-8");
     registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(), 80));
     manager = new ThreadSafeClientConnManager(params, registry);
     httpClient = new DefaultHttpClient(manager, params);
     host = new HttpHost(hostname, 80, "http");
     uri.path(urlPath);
  
     this.urlPath = urlPath;
     this.hostname = hostname;
    }
  
    public UrlParamsHelper(Parcel in) {
     //unpack the state
    }
  
    public void addQueryString(String key, String value) {
     uri.appendQueryParameter(key, value);
    }
  
    public HttpGet buildGetQuery() {
     return new HttpGet(uri.build().toString());
    }
  
    public HttpClient getHttpClient() {
     return httpClient;
    }
  
    public HttpHost getHttpHost() {
     return host;
    } 
  
    @Override
    public int describeContents() {
     return 0;
    }
  
    @Override
    public void writeToParcel(Parcel dest, int flags) {
     //Parcel the entire state of the object
    }
  
    //Constructs the parcel again - REQUIRED
        public static final Parcelable.Creator&lt;UrlParamsHelper&gt; CREATOR = new Parcelable.Creator&lt;UrlParamsHelper&gt;() {
         public UrlParamsHelper createFromParcel(Parcel in) {
             return new UrlParamsHelper(in);
         }
  
         public UrlParamsHelper[] newArray(int size) {
          throw new UnsupportedOperationException();
             //return new UrlParamsHelper[size];
         }
     };
   }
  </code></pre>