Android 使用 Bundle 提供从 String 值到各种 Parcelable 类型的映射。
对于活动:-
Intent in = new Intent(Sender.this, Receiver.class);
in.putString(key, value)
startActivity(in);
对于片段使用捆绑包:-
Fragment fragment = new Fragment();
Bundle bundle = new Bundle();
bundle.putInt(key, value);
fragment.setArguments(bundle);
编辑您的场景:我认为更好的选择是创建应用程序池。
请按照以下步骤操作:-
启动应用程序池:-
ApplicationPool pool = ApplicationPool.getInstance();
详情页修改数据并添加到池中
pool.put("key", object);
从池中获取列表页修改后的数据
Object object = (Object) pool.get("key");
重要提示:- 获取数据后通知listview或gridview
应用程序池类文件
public class ApplicationPool {
private static ApplicationPool instance;
private HashMap<String, Object> pool;
private ApplicationPool() {
pool = new HashMap<String, Object>();
}
public static ApplicationPool getInstance() {
if (instance == null) {
instance = new ApplicationPool();
}
return instance;
}
public void clearCollectionPool() {
pool.clear();
}
public void put(String key, Object value) {
pool.put(key, value);
}
public Object get(String key) {
return pool.get(key);
}
public void removeObject(String key) {
if ((pool.get(key)) != null)
pool.remove(key);
}
}