Removing extras from passed-in Intent

前端 未结 3 932
天命终不由人
天命终不由人 2021-02-01 00:22

I have a search screen which can be launched from clicking on a \"name\" field of another screen.

If the user follows this workflow, I add an extra to the Intent\'s Extr

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 01:12

    While @Andrew's answer may provide a means for removing a specific Intent extra, sometimes it is necessary to clear ALL of the intent extras and, in this case, you will want to use

    Intent.replaceExtras(new Bundle())
    

    Source code of replaceExtras:

    /**
     * Completely replace the extras in the Intent with the given Bundle of
     * extras.
     *
     * @param extras The new set of extras in the Intent, or null to erase
     * all extras.
     */
    public @NonNull Intent replaceExtras(@NonNull Bundle extras) {
        mExtras = extras != null ? new Bundle(extras) : null;
        return this;
    }
    

提交回复
热议问题