如何在不覆盖的情况下将所有映射从 Bundle 传输到另一个 bundle?

How to transfer all mappings from Bundle to another bundle without overwriting it?

我试过了,但它会覆盖现有的包:

Bundle b1 = new Bundle();
b1.putString("name", "Abraham");
Intent i = getIntent();
Bundle b2 = i.getExtras();
b1.putAll(b2);

比我失去亚伯拉罕...

你在这里做的是: //创建一个新的包

 Bundle b1 = new Bundle();

//将一些值放入该包中

b1.putString("name", "Abraham");

//创建一个新的Intent

Intent i = getIntent();

这里没有像这样将 b1(bundle) 分配给您的意图

i.putExtras(b1);

//这里你从意图中得到了一个空包。

捆绑包 b2 = i.getExtras();

// 所以你在这里没有得到任何包并且得到一个异常

b1.putAll(b2);

您只需将您的包分配给 intent。就像上面用粗体提到的那样。