搜尋

首頁  >  問答  >  主體

Android中,既然intent可以傳遞鍵值對數據,為什麼要把intent和bundle結合起來使用呢?

如題所述,bundle和intent都可以存放鍵值對數據,對數情況下直接用intent就好了,為什麼還有intent+bundle這種搭配呢?

大家讲道理大家讲道理2821 天前865

全部回覆(3)我來回復

  • 世界只因有你

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

    你就算用 intent傳 裡面也會自動產生一個bundle的。
    所以其實都是用bundle

    回覆
    0
  • 天蓬老师

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

    一樓已經回答的很正確了,我只是貼出個源碼來:

        /**
         * 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;
        }

    回覆
    0
  • 给我你的怀抱

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

    好像是bundle能傳遞的資料型態多?

    回覆
    0
  • 取消回覆