android – What is the difference between getExtras and getBundleExtras?-ThrowExceptions

Exception or error:

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

How to solve:

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.

###

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(...)

Leave a Reply

Your email address will not be published. Required fields are marked *