为什么启动我的活动不包含额外的数据我把我送到给startActivity的意图的意图()?意图、我的、把我、不包含

2023-09-12 22:20:24 作者:腥风血雨

我解释了这个原本严重。这是我的问题:我发送到startActivity()方法的意图,包括私人领域,MMAP,它是一个包含我送到putExtra()的字符串的映射。当目标活动开始,调用getIntent()返回的意图并不包含这些值。该MMAP字段是空。显然,一些在视图层级或启动该新的活动OS的一部分的肠子创建了一个新的意图传递给它,因为对象ID是不同的。

I explained this badly originally. This is my question: The Intent I send to the startActivity() method, contains a private field, mMap, which is a Map containing the strings I sent to putExtra(). When the target activity starts, a call to getIntent() returns an Intent that does not contain those values. The mMap field is null. Obviously, something in the bowels of the View hierarchy or the part of the OS that started the new activity created a new Intent to pass to it, since the object IDs are different.

但是,为什么?为什么是putData()值不进行fowrard新的意图是什么?

But why? And why are the putData() values not carried fowrard to the new Intent?

这是启动新活动活动延伸活动。下面是启动code:

The activity that starts the new activity extends Activity. Here's the startup code:

public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case 4:
        i = new Intent(this, StatList.class);
        i.putExtra("Name1", "Test1");
        i.putExtra("Name3", "Test2");
        startActivity(i);
     }   
 }

我已经试过键值有和没有(推荐)完整的软件包名称preFIX。

I've tried the key values with and without the (recommended) complete package name prefix.

在Eclipse调试器,我已经验证了值的球员的名字被插入到i.mExtras.mMap正常。

In the Eclipse debugger, I have verified the values for the player names are being inserted into i.mExtras.mMap properly.

下面是从startee的code:

Here's the code from the startee:

public class StatList extends ListActivity {
private final StatsListAdapter statsAdapter;

public StatList() {
    statsAdapter = StatsListAdapter.getInstance(this);
} // default ctor

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent i = getIntent();
    final Bundle extras = i.getExtras();
          < more code here >
} 

当执行到达这个方法,mIntent.mExtras.mMap是空,然后mIntent.mExtras.mParcelledData现在包含一些值,不看明智的(这是空当startActivity()被调用)。 getIntent()返回mIntent。

When execution gets to this method, mIntent.mExtras.mMap is null, and mIntent.mExtras.mParcelledData now contains some values that don't look sensible (it was null when startActivity() was called). getIntent() returns mIntent.

我也试着startActivityForResult(),具有相同的结果。

I've also tried startActivityForResult(), with the same result.

这是我在网上和放大器看到文档和样品;在示例应用程序,这应该很容易。我找到了另一种方式来满足我的燃眉之急,但我想知道是否有人能帮助我理解为什么一些这个简单的不能正常工作。

From the docs and the samples I've seen online & in the sample apps, this should be easy. I've found another way to meet my immediate need, but I'd like to know if anyone can help me understand why something this simple doesn't work.

推荐答案

在您的主要活动:

i = new Intent(this, StatList.class);
i.putExtra("Name1", "Test1");
i.putExtra("Name3", "Test2");
startActivity(i);

然后在 StatList.class

Bundle extras = getIntent().getExtras();
String name1 = extras.getString("Name1");
String name3 = extras.getString("Name3");
Log.i("StatList", "Name1 = " + name1 + " && Name3 = " + name3)
 
精彩推荐