search

Home  >  Q&A  >  body text

In Android, since intent can pass key-value pair data, why should intent and bundle be used together?

As mentioned in the title, both bundle and intent can store key-value pair data. In logarithmic cases, just use intent directly. Why is there such a combination of intent+bundle?

大家讲道理大家讲道理2742 days ago812

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 13:37:37

    Even if you use intent to pass it, a bundle will be automatically generated.
    So in fact, bundles are used

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-16 13:37:37

    The first floor has already answered it correctly, I just posted the source code:

        /**
         * Add extended data to the intent.  The name must include a package
         * prefix, for example the app com.android.contacts would use names
         * like "com.android.contacts.ShowAll".
         *
         * @param name The name of the extra data, with package prefix.
         * @param value The String data value.
         *
         * @return Returns the same Intent object, for chaining multiple calls
         * into a single statement.
         *
         * @see #putExtras
         * @see #removeExtra
         * @see #getStringExtra(String)
         */
        public Intent putExtra(String name, String value) {
            if (mExtras == null) {
                mExtras = new Bundle();
            }
            mExtras.putString(name, value);
            return this;
        }

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:37:37

    It seems that the bundle can transfer many data types?

    reply
    0
  • Cancelreply