标签:activity 传递 数据 bundle android
WeakReferences
)Serializable
:
it‘s error prone and horribly slow. So in general: stay
away from Serializable
if
possible.FLAG_ACTIVITY_CLEAR_TASK
或者 BroadcastReceiver 杀掉其他的activity。
public class DataHolder {
private String data;
public String getData() {return data;}
public void setData(String data) {this.data = data;}
private static final DataHolder holder = new DataHolder();
public static DataHolder getInstance() {return holder;}
}
DataHolder.getInstance().setData(data);
String data = DataHolder.getInstance().getData();
public class DataHolder {
private static String data;
public static String getData() {return data;}
public static String setData(String data) {this.data = data;}
}
启动之前设置数据,新的activity获取数据。public class DataHolder {
Map<String, WeakReference<Object>> data = new HashMap<String, WeakReference<Object>>();
void save(String id, Object object) {
data.put(id, new WeakReference<Object>(object));
}
Object retrieve(String id) {
WeakReference<Object> objectWeakReference = data.get(id);
return objectWeakReference.get();
}
}
启动之前:DataHolder.getInstance().save(someId, someObject);
新activity中:DataHolder.getInstance().retrieve(someId);
这里可能需要通过intent传递id,如果数据唯一,id都可以不传递的。save() retrieve()中id都固定即可。版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:activity 传递 数据 bundle android
原文地址:http://blog.csdn.net/rflyee/article/details/47431633