0
我的問題如下,我有一個hashmap,我已初始化在主要活動中,我的對象類確實實現了seriliazable。我的問題是我可以將對象傳遞給另一個活動並讀取原始hasmap的值,但是當我在新活動中向hashmap添加新值時,實際上並沒有在活動結束時更改原始hashmap。Android可串行化傳遞數據並返回更改的數據
這是林如何傳遞到其他活動
HashMap<String,Book> detail1 = new HashMap<String,Book>;
Intent i2 = new Intent(MainActivity.this, PlaceHold.class);
bundle.putSerializable("hashMap",detail1);
i2.putExtras(bundle);
startActivity(i2);
這是其他活動如何使用傳遞的值
HashMap<String,Book> hashMap = HashMap<String,Book>) getIntent().getSerializableExtra("hashMap");
hashMap.put(bookIsbn,new Book(bookTitle,bookIsbn,bookFee,bookAuthor));
finish();
我的問題是,當我通過加入書不會出現hashamp去其他班級。只有在MainActivity oncreate上設置的默認值存在。
返回更新的HashMap太感謝你了。我不確定要使用什麼。研究了setActivityForResult和它的工作。:) –