我有主要 Activity 和另外两个 Activity (第二个和第三个)。我在主要 Activity 和 Intent 中创建了一个包,就像这样Intent intent = new Intent(this,second.class);
我想在第三个 Activity 中使用 get extras。像 bundle comes = getIntent().getExtras();
。有可能吗?为什么不可以?
最佳答案
and I want to use get extras in third activity. like bundle comes = getIntent().getExtras();. is it possible or why not?
您只能从将启动您的第三个 Activity 的 Intent 中getExtras()。所以换句话说,如果您的 MainActivity 启动第三个 Activity,您可以在第三个 Activity 中检索数据,如果您将它们附加到启动第三个 Activity 的 Intent 中:
// this is calling from MainActivity
Intent intent = new Intent(this, Third.class);
intent.putExtras(bundle);
如果 MainActivity 不启动第三个 Activity,则您无法执行此操作。但是您可以从第二个 Activity 中检索第三个 Activity 中的数据(在这里您必须再次将数据附加到 Intent):
// this is calling from SecondActivity
Intent intent = new Intent(this, Third.class);
intent.putExtras(bundle);
关于android - 在更多 Activity 中使用 bundle ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331575/