What is the difference between getExtras and getBundleExtras?

非 Y 不嫁゛ 提交于 2019-12-22 01:33:52

问题


Could someone please explain to me what is the difference between getExtras() and getBundleExtras()?


回答1:


getBundleExtra("String") gets a bundle named String.

getExtras() gets a bundle with all of the items placed into the array.

A bundle can be placed using a putExtra(Bundle, String tag) command, so the getBundleExtra() will return that value.




回答2:


Worth notting is the fact that getExtras() returns copy of the all items placed in the intent, its implementation looks like this:

4433    public Bundle getExtras() {
4434        return (mExtras != null)
4435                ? new Bundle(mExtras)
4436                : null;
4437    }

so its not a good idea to call intent.getExtras().putInt(...)



来源:https://stackoverflow.com/questions/9577024/what-is-the-difference-between-getextras-and-getbundleextras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!