从传入的意图删除临时演员 [英] Removing extras from passed-in Intent

查看:109
本文介绍了从传入的意图删除临时演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可以点击在另一个屏幕上的姓名字段中展开搜索屏幕。

如果用户遵循此工作流,我添加一个额外的名为搜索的意图的附加功能。这额外的使用填充姓名字段作为其值的文本。在创建检索屏幕,即额外用作搜索参数和搜索是针对用户自动启动。

不过,由于Android破坏并重新创建Activitys当屏幕旋转,旋转手机再次导致自动搜索。正因为如此,我想删除执行初始搜索时,搜索额外从活动的意图。

我已经试过这样做,像这样:

 捆绑额外= getIntent()getExtras()。
    如果(临时演员!= NULL){
        如果(extras.containsKey(搜索)){
            mFilter.setText(extras.getString(搜索));
            launchSearchThread(真正的);
            extras.remove(搜索);
        }
    }
 

然而,这是行不通的。如果我再旋转屏幕,搜索额外仍存在于活动的意图的附加功能。

任何想法?

解决方案

我有工作。

这似乎getExtras()的创建的意图的额外副本

如果我用下面的行,这工作正常:

  getIntent()removeExtra(搜索)。
 

getExtras()

来源$ C ​​$ C

  / **
 *检索从意图扩展数据的地图。
 *
 返回:所有的演员$ P $与putExtra pviously添加的地图()
 *或NULL,如果没有已被添加。
 * /
公共捆绑getExtras(){
    返程(mExtras!= NULL)
            ?新的捆绑(mExtras)
            : 空值;
}
 

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 Extras called "search". This extra uses the text populating the "name" field as its value. When the search screen is created, that extra is used as a search parameter and a search is automatically launched for the user.

However, since Android destroys and recreates Activitys when the screen rotates, rotating the phone causes an auto-search again. Because of this, I'd like to remove the "search" extra from the Activity's Intent when the initial search is executed.

I've tried doing this like so:

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey("search")) {
            mFilter.setText(extras.getString("search"));
            launchSearchThread(true);
            extras.remove("search");
        }
    }

However, this isn't working. If I rotate the screen again, the "search" extra still exists in the Activity's Intent's Extras.

Any ideas?

解决方案

I have it working.

It appears getExtras() creates a copy of the Intent's extras.

If I use the following line, this works fine:

getIntent().removeExtra("search");

Source code of getExtras()

/**
 * Retrieves a map of extended data from the intent.
 *
 * @return the map of all extras previously added with putExtra(),
 * or null if none have been added.
 */
public Bundle getExtras() {
    return (mExtras != null)
            ? new Bundle(mExtras)
            : null;
}

这篇关于从传入的意图删除临时演员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆