我正在尝试在两个 Activity 之间传递 int
值。在第一个 Activity 中,我编写了代码:
Class nextView = Class.forName("com.test.NextFile");
Intent nextIntentTest = new Intent(CurrentFile.this, NextFile.class);
nextIntentTest.putExtra("passingName",nameofvar);
startActivity(nextIntentTest);
并且,在第二个 Activity 中,
Intent intentTest = this.getIntent();
int counter = intentTest.getIntExtra("passingName",-1);
我不知道为什么,但我总是得到默认值(-1)。我对其他类和变量做了几乎相同的事情,一切都很好。也许问题出在 public class NextFile extends ListActivity
而不是 public class NextFile extends Avtivity
?
有人可以帮助我吗?
最佳答案
尝试
Bundle c = new Bundle();
c.putInt("passingName",nameofvar);
yourintent.putExtras(c);
发布值
和
Bundle b = getIntent().getExtras();
int counter = b.getInt("passingName"); to retrieve it
关于java - 在两个 Activity 之间传递 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16609735/