android uri parcel,如何在Android中正确使用Parcelable类

我有一个要通过意图发送到服务类的类(下).我已经实现了Parcelable接口,但是不确定如何实际发送和检索包括对象当前状态在内的整个对象.

尤其是

@Override

public void writeToParcel(Parcel dest, int flags) {

//I need this to send the entire state of the object

}

public UrlParamsHelper(Parcel in) {

//I need this to unpack the state of the object

}

这是实际的课程

/*

* 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 CREATOR = new Parcelable.Creator() {

public UrlParamsHelper createFromParcel(Parcel in) {

return new UrlParamsHelper(in);

}

public UrlParamsHelper[] newArray(int size) {

throw new UnsupportedOperationException();

//return new UrlParamsHelper[size];

}

};

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值