- /**
- * 由于Intent中传输自定义对象存在大小限制,并且对象都要实现Serializable或Parcelable接口,比较麻烦
- * 因此实现此对象,把自定义的对象存在静态内存中,使用后手动释放
- * 实现方式:泛型+单例
- * @author Yorling.Lin
- * @param <T>
- */
- @SuppressWarnings("unchecked")
- public class IntentCacheHelper<T> {
- private static IntentCacheHelper<?> instance;
- private T t;
- public static <T> IntentCacheHelper<T> getInstance(Class<T> cls)
- {
- if(instance == null)
- {
- instance = new IntentCacheHelper<T>();
- }
- return (IntentCacheHelper<T>) instance;
- }
- public void setObject(T t)
- {
- this.t = t;
- }
- public T getObject()
- {
- return this.t;
- }
- public void recycle()
- {
- t = null;
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1710201410661.html
来源: http://www.codesnippet.cn/detail/1710201410661.html